How to Install Node.js on Debian 11

Install Node.js on Debian 11

In this article, we will have explained the necessary steps to install Node.js on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

NodeJs is a JavaScript framework that allows users to easily develop autonomous network applications for general-purpose programming. NodeJs is free to make web application development more uniform and integrated through the use of JavaScript on both the front and back ends. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

Install Node.js on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade
sudo apt install build-essential

Step 2. Install Node.js and NPM on the Debian system.

  • Installing Node.js from Debian Repository.

Run the below command to install NodeJs and npm on Debian 11:

sudo apt install nodejs npm
  • Installing Node.js using NodeSource PPA.

We will need to install the PPA in order to install Node.js 16. From your home directory, use the curl command:

curl -fsSL | sudo -E bash -

Then, run the apt update and then install Node.js:

sudo apt update
sudo apt install nodejs

Verify installation by checking the version number of NodeJs:

node -v

Also, check the version of npm to verify its installation:

npm -v

Step 3. Testing Node.js.

Now create a sample JavaScript file using nano editor:

nano test.js

Add the following file:

const http = require(‘http’);
const hostname = ‘localhost’;
const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader(‘Content-Type’, ‘text/plain’);
res.end(‘Hello World\n’);
server.listen(port, hostname, () => {
console.log(‘Server running at http://${hostname}:${port}/’);

Save and close, then start application run below mentioned command below:

node sample.js

Finally, Run the below command to test the application on another terminal:

curl http://localhost:3000

That’s all you need to do to install the Node.js on Debian (Bullseye). I hope you find this quick tip helpful. For further reading Node.js and NPM on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.