How to Install Node.js on Debian 11 Server (Setup/ Configure)

How to Install Node.js on Debian 11 Server. There are multiple programming languages available online that developers can use to build a web application. But it is recommended to select the right tool to execute a better project. Today, many developers consider the Node.js framework. It is a server side programming and a runtime environment, based on Chrome’s V8 JavaScript engine.

Node.js framework is more versatile and supports both front end and back end coding and there are many advantages to choosing it . Here, we will discuss the Node.js framework in detail and its benefits.

In this tutorial we will show you 3 methods for installing Nodejs on Debian 11:  Install Node.js from Debian Repository, from NodeSource and install Node.js with NVM. We believe in showing multiple methods of installing Node.js as it will be beneficial for any user.

What is Node.js framework

Released in 2009 by Ryan Dahl, Node.js is a free, open source platform designed to aid developers in creating fast and dynamic web pages and network applications.

Node.js is highly compatible with OS X, Linux, and Microsoft Windows platforms. Its framework is a platform that helps developers use JavaScript to write front end and back end coding and command line tools.

The framework is a collection of libraries and tools built on Node, including:

Express.js – It is an asynchronous Model View Controller framework with high speed I/O that helps direct servers and routes, renders HTML Pages, and enables developers to design different web applications.

AdonisJS – It is a Node.js framework with an MVC like structure that involves less use of code when writing web applications, runs multiple test modules, and focuses on being a stable framework.

MeteorJS – An open source Node.js web framework that produces cross platform codes and supports other frameworks.

NestJS – Another Node.js framework that helps the developer in building efficient server side applications. It supports JavaScript, Object Oriented Programming (OOP), TypeScript, etc.

SailsJS – It is an MVC based framework that uses Node.js as a base. The framework is supported to ease the building process of customized web applications and API.

Hapi.js, Loopback.io, Feathers.js, MEAN.JS, and KoaJS are a few other Node.js Frameworks.

Follow this post to learn how to Install Node.js on Debian 11 Server.

Benefits of Node.js Framework

Here are a few advantages of using Node.js framework:

Fast-processing and event based model (V8 engine with Non blocking Input/Output and asynchronous request handling).

Easy to Learn and Scalable – Node.js framework uses JavaScript to write codes which is one of the popular programming languages, and most developers find it easy to work on it. One can learn Node.js in a short time. Also, it offers high scalability and ensures that the servers are processing requests seamlessly.

Fullstack JS Benefit – Node.js serves both clients and server side applications, making it a full stack JavaScript. As a result, you do not require additional developers to perform backend and front end developments separately. You can save both time and money using the Node.js frameworks.

Event based model  with regards to its asynchronous model Node.js server is a popular choice for online gaming or video conferences.  Please take a look at Kafka for real time streaming also for a solution that requires constantly updated data.

Offers High Performance – Node.js uses Google’s V8 JavaScript engine to interpret the JavaScript code directly into the machine code. Thus, making the process of code implementation easier, faster, and more effective. The code execution speed is also enhanced as most frameworks support non blocking I/O operations.

Manages Requests Simultaneously – Node.js supports non blocking I/O systems, which help developers to process multiple requests at the same time. Compared to other languages like Ruby or Python, Node.js handles concurrent requests more efficiently. All the incoming requests are executed in a systematic manner and quickly.

Scalable technology for microservices with the use of Docker technology. Node.js is known to outperform Godaddy in terms of performance. 

JSON support if you need to build for example RESTful APIs for NoSQL database like MongoDB,  this seamless communication with one of the main data transfer standards is another advantage of the JavaScript ecosystem as Node.js does it without converting between binary models and uses JavaScript.

Next in this post is how to install Node.js on Debian 11.

Install Node.js via Debian Repository

The simple and easiest way to install Node.js is to install it from the Debian default repository. The latest version included in the Debian 11 repository is 12.22.5.

You can check the available Node.js version using the following command:

				
					apt show nodejs
				
			

You will get the package information in the following output:

				
					Package: nodejs
Version: 12.22.5~dfsg-2~11u1
Priority: optional
Section: web
Maintainer: Debian Javascript Maintainers <pkg-javascript-devel@alioth-lists.debian.net>
Installed-Size: 940 kB
Provides: node-types-node (= 12.20.19~12.22.5~dfsg-2~11u1)
Depends: libc6 (>= 2.2.5), libnode72 (= 12.22.5~dfsg-2~11u1)
Recommends: ca-certificates, nodejs-doc
Suggests: npm
Conflicts: nodejs-legacy
Breaks: node-babel-runtime (<< 7), node-typescript-types (<< 20210110~)
Replaces: nodejs-legacy
Homepage: https://nodejs.org/
Tag: devel::interpreter, devel::lang:ecmascript, devel::runtime, devel::web,
 implemented-in::c++, implemented-in::ecmascript,
 interface::commandline, interface::shell, protocol::dns,
 protocol::http, protocol::tcp, role::program, scope::application,
 works-with-format::json
Download-Size: 147 kB
APT-Sources: http://debian.gtisc.gatech.edu/debian bullseye/main amd64 Packages
Description: evented I/O for V8 javascript - runtime executable
 Node.js is a platform built on Chrome's JavaScript runtime for easily
 building fast, scalable network applications. Node.js uses an
 event-driven, non-blocking I/O model that makes it lightweight and
 efficient, perfect for data-intensive real-time applications that run
 across distributed devices.

				
			

Next, update the Debian 11 repository by running the following command:

				
					apt-get update -y
				
			

Once the repository is up to date, you can install the Node.js and NPM package using the following command:

				
					apt-get install nodejs npm -y
				
			

After the successful installation, verify the Node.js version using the following command:

				
					node --version
				
			

You will get the following output:

				
					v12.22.5
				
			

If you want to uninstall the Node.js package from your system, run the following commands:

				
					apt-get remove nodejs npm --purge
apt-get autoremove
apt-get clean
				
			

Install Node.js Using NodeSource Repository

The NodeSource is an online repository that contains open source Node.js packages. It helps developers to install multiple Node.js versions in the same server.

First, install the curl command line utility using the following command:

				
					apt-get install curl -y
				
			

Next, add the NodeSource repository for Node.js version 17 using the following command:

				
					apt-get install nodejs -y
				
			

After the installation, verify the Node.js version with the following command:

				
					node --version
				
			

You will get the following output:

				
					v17.9.0
				
			

Install Node.js Using NVM

NVM stands for “Node Version Manager” is a Node package manager that allows you to install, manage and switch between different Node versions with ease. It provides a command line interface to install and manage different Node.js versions.

First, run the following command to install the NVM:

				
					curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
				
			

You will get the following output:

				
					/usr/lib
├── corepack@0.10.0
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:

     $ nvm use system
     $ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

				
			

Once the NVM is installed, close and reopen your terminal to start using nvm or run the following to use it now:

				
					export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

				
			

Next, verify the NVM version using the following command:

				
					nvm --version
				
			

You will get the following output:

				
					0.39.1
				
			

You can see all available Node.js version using the following command:

				
					nvm list-remote
				
			

You will get a list of all Node.js versions in the following output:

				
					        v16.9.1
       v16.10.0
       v16.11.0
       v16.11.1
       v16.12.0
       v16.13.0   (LTS: Gallium)
       v16.13.1   (LTS: Gallium)
       v16.13.2   (LTS: Gallium)
       v16.14.0   (LTS: Gallium)
       v16.14.1   (LTS: Gallium)
       v16.14.2   (LTS: Gallium)
       v16.15.0   (Latest LTS: Gallium)
        v17.0.0
        v17.0.1
        v17.1.0
        v17.2.0
        v17.3.0
        v17.3.1
        v17.4.0
        v17.5.0
        v17.6.0
        v17.7.0
        v17.7.1
        v17.7.2
        v17.8.0
        v17.9.0
        v18.0.0
        v18.1.0
        v18.2.0

				
			

Now, install the Node.js version 16.0.0 using the following command:

				
					nvm install v16.0.0
				
			

You will get the following output:

				
					Downloading and installing node v16.0.0...
Downloading https://nodejs.org/dist/v16.0.0/node-v16.0.0-linux-x64.tar.xz...
####################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.0.0 (npm v7.10.0)
Creating default alias: default -> v16.0.0

				
			

To verify the Node.js version, run the following command:

				
					node --version
				
			

You will get the following output:

				
					v16.0.0

				
			

To list all installed Node.js versions, run the following command:

				
					nvm ls
				
			

You will get the following output:

				
					->      v16.0.0
         system
default -> v16.0.0
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.0.0) (default)
stable -> 16.0 (-> v16.0.0) (default)
				
			

To install the latest stable version, run the following command:

				
					nvm install --lts
				
			

You should see the following output:

				
					Installing latest LTS version.
Downloading and installing node v16.15.0...
Downloading https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.xz...
####################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.15.0 (npm v8.5.5)

				
			

To set the default Node.js version to LTS, run the following command:

				
					nvm use --lts
				
			

You should see the following output:

				
					Now using node v16.15.0 (npm v8.5.5)

				
			

If you want to remove Node.js version 17.0.0, run the following command:

				
					nvm uninstall v17.0.0
				
			

Create a Simple Node.js Application

First, create a file named app.js using the following command:

				
					nano app.js
				
			

Add the following code:

				
					#!/usr/bin/env node
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8000, 'localhost');
console.log('Server running at http://localhost:8000/');

				
			

Set the executable permission to the app.js file using the following command:

				
					chmod +x ./app.js
				
			

Run the Node.js application using the following command:

				
					./app.js &

				
			

You will get the following output:

				
					Server running at http://localhost:8000/

				
			

Now, open another terminal and access your Node.js application using the following command:

				
					curl http://localhost:8000
				
			

You will get the following output:

				
					Hello World
				
			

Great work! We have learned How to Install Node.js on Debian 11 Server in 3 ways. 

How to Install Node.js on Debian 11 Server Conclusion

NodeJs makes the web application development more integrated through JavaScript usage on both the front and back end development as it is JavaScript framework that allows users to easily develop autonomous network applications for general purpose programming. 

In the above guide, we learned three different ways to install Node.js on Debian 11. You can now choose your preferred ways to install Node.js on your server. For more information, visit the Node.js documentation page. 

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x