Skip to main content

13 posts tagged with "nodejs"

View All Tags

· 2 min read
Sivabharathy

To install a specific version of Node.js on Ubuntu 24.04, you can use the NodeSource binary distributions. Here are the steps to do so:

  1. Update your package index:

    sudo apt update
  2. Install the required dependencies:

    sudo apt install curl software-properties-common
  3. Add the NodeSource repository:

    • To install a specific version, such as Node.js 16, use:
      curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
  4. Install Node.js:

    sudo apt install nodejs

· 2 min read
Sivabharathy

To free up a port that is currently being used by a process on Ubuntu, you need to identify the process and then terminate it. Here's how you can do that:

  1. Identify the process using the port: Use the lsof or netstat command to find the process ID (PID) of the process using the port. For example, to check port 3000:

    sudo lsof -i :3000

    Or using netstat:

    sudo netstat -tuln | grep :3000
  2. Find the PID: The output of lsof will look something like this:

    COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    node 12345 user 22u IPv4 123456 0t0 TCP *:3000 (LISTEN)

    Note the PID of the process (in this example, 12345).

  3. Kill the process: Use the kill command to terminate the process using its PID. For example:

    sudo kill -9 12345

    Replace 12345 with the actual PID from the previous step. The -9 option sends a SIGKILL signal, which forces the process to terminate immediately.

· 3 min read
Sivabharathy

Publishing your own public npm package involves several steps, from setting up your package to publishing it to the npm registry.

Here's a step-by-step guide to help you publish your own npm package:

1. Set Up Your Package

  1. Create a New Directory for Your Package:

    mkdir my-awesome-package
    cd my-awesome-package
  2. Initialize a New npm Package: Run the following command and answer the prompts to create a package.json file:

    npm init

    Alternatively, you can use npm init -y to automatically generate a package.json file with default values.

2. Develop Your Package

  1. Create Your Package Files: For example, create an index.js file:

    // index.js
    function helloWorld() {
    console.log('Hello, world!');
    }

    module.exports = helloWorld;