https://tecadmin.net/install-latest-nodejs-npm-on-debian/


Node.js is a platform built on Chrome’s V8 JavaScript engine.Nodejs can used for easily building fast, scalable network applications. Latest version node.js ppa is maintaining by its official website. We can add this PPA to Debian 10 (Buster)Debian 9 (Stretch) Debian 8 (Jessie) and Debian 7 (Wheezy) systems. Use this tutorial to install latest Nodejs & NPM on Debian 10/9/8/7 systems.

To install specific nodejs version, Visit our tutorial Install Specific Nodejs Version with NVM.

Install nodejs on Debian

Step 1 – Add Node.js PPA

You are required to add Node.js PPA to your system provided by the Nodejs official website. We also need to install the software-properties-common package if not installed already. You can choose either to install the latest Node.js version or LTS version.

For Latest Release

sudo apt-get install curl software-properties-common
curl -sL https://deb.nodesource.com/setup_13.x | sudo bash -

For LTS Release

sudo apt-get install curl software-properties-common
curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -

Step 2 – Install Node.js on Debian

After adding the required PPA file lets install Nodejs package. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.

sudo apt-get install nodejs

Step 3 – Check Node.js Version

After completeing the installation, check and verify the installed version of Node.js and NPM. You can find more details about current version on node.js official website.

node -v 

v13.0.1

Also, check the version of NPM.

npm -v 

6.12.0

Step 4 – Create Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with “Hello World!” text. Create a file http_server.js

vim http_server.js

and add the 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/');

Now start the node service using the following command.

node http_server.js

Server running at http://127.0.0.1:3000/

Web server has been started on port 3000. Now access http://127.0.0.1:3000/ url in browser.