how to install nodejs and npm on ubuntu

    Posted in Linux Servers on Aug 22, 2019


    Add Nodejs Package on Server

    We are going to add the latest package on server so that we can install latest nodejs

    sudo apt-get install curl
    curl -sL | sudo -E bash -

    Install Node.js on Ubuntu

    sudo apt-get install nodejs

    Check Node.js Version on server

    node -v 

    Check NPM Version on server

    npm -v 

    Node and NPm is installed sucessfully !! Now we are going to create demo node js server

    vim server.js

    After creating a file, please add the following content :

    var http = require('http');
    http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello Node Server\n');
    }).listen(5000, "");
    console.log('Server running at');

    Please start the Node application using following command:

    node server.js

    After that you will see the output

    debugger listening on port 5858
    Server running at

    Note : if you want to set node js on public ip of server you can repalce the ip to your server ip . Also need to open the define port in server firewall.

    Services Cloudtechtiq offers: