Node.js is an open-source, cross-platform for general-purpose programming and built on Chrome’s JavaScript run-time environment that easily executes JavaScript code outside of a browser and
easily building fast, scalable network applications.The latest version of node.js ppa is maintaining by its own official website.In this blog post tutorial we are going to show you step by step instructions to add this PPA to your Ubuntu 19.10, 18.04 LTS, 16.04 LTS (Trusty Tahr) and 14.04 LTS (Xenial Xerus) systems
and install Latest Nodejs to on Linux VPS with the simple commands
Step 1 – Add Node.js PPA
As per requirements this is depending upon your choice to select which version to install in your system and Before installing the latest version of Node.js in your system, you must add its PPA to Ubuntu.Node.js package is available in the LTS release and the current release. Let’s add the PPA to your system to install Nodejs on Ubuntu.
Use below Command For Current Release:
$ sudo apt-get install curl $ curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
Use below Command for LTS Release
$ sudo apt-get install curl $ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
Note :- In this tutorial, I am going to use the latest current release of nodejs and add their PPA to my system.
Step 2 – Install Node.js on Ubuntu System
Now we can successfully add Node.js PPA to the Ubuntu system and will execute the below command to install Nodejs on Ubuntu system using apt-get. This command will be also going to install NPM with node.js as well as many other dependent packages on Ubuntu System.
$ sudo apt-get install nodejs
Step 3 – Check Version of Node.js and NPM
After installation of node.js we will check and verify the installed version of node.js.
We can use the below commands to view the installed node.js & npm version number.
$ node -v
v13.3.0
& also checking npm version
$ npm -v
6.13.1
Step 4 – Create Demo on Web Server
If you want to check and verify your node.js installed. Let’s create a web server with “Hello World” text.
Creating a file with name test_server.js like below:-
# vim test_server.js
After creating a file adding the some following content
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(3000, "127.0.0.1"); console.log('Server running at http://127.0.0.1:3000/');
After that we should save the file and run below commands to start the server.
node test_server.js
You should see an output that reads:
debugger listening on port 5858 Server running at http://127.0.0.1:3000/
You can also start the application with debugging through below commands.
$ node --inspect server.js Debugger listening on ws://127.0.0.1:9229/938cf97a-a9e6-4672-922d-a22479ce4e29 For help, see: https://nodejs.org/en/docs/inspector Server running at http://127.0.0.1:3000/
Now we can open the browser and type server hostname or IP address followed by port number 3000 like below:-
http://localhost:3000
then we will see a default page with Hello World.