
Node.js is an open-source, cross-platform JavaScript runtime environment for developing web applications. The Node Package Manager (NPM) builds and manages dependency packages for Node.js. Node.js and NPM allow you to use JavaScript for server-side scripting.
This article explains how to install Node.js and NPM on Debian 12. You will install Node.js and manage multiple versions using the NVM (Node Version Manager).
Before you begin:
The Node.js release cycle includes a new version that enters the Current release status for six months. Even-numbered versions transition to an Active LTS (Long-Term Support) status that lasts for 12 months followed by a maintenance status for 18 months. When selecting a Node.js version, consider the release stability, performance, features, and compatibility with your project environment.
The following Node.js releases are available when selecting a version:
Node.js is available in the default package repositories on Debian 12, but the available version might be out of date. Follow the steps below to enable the NodeSource PPA repository and install Node.js:
Download the latest Nodesource PPA repository script for your target Node.js version. For example, Node.js version 22.x.
Visit the official NodeSource distributions to verify the latest Node.js repository information packages.
Run the script to install the repository and update your server's package information index.
Install Node.js and NPM.
View the Node.js version.
Your output should be similar to the one below.
View the NPM version.
Output:
Follow the steps below to test your Node.js installation and run a sample HTTP server application that outputs a Greetings from Vultr message when you access it using a web browser.
Create a new project directory. For example, nodeapp.
Switch to the nodeapp directory.
Create a new greetings.js file using a text editor like vim.
Add the following contents to the greetings.js file.
Save and close the file.
The above application code starts a new HTTP server that listens for incoming requests on port 3000 and displays a Greetings from Vultr message.
Run the application using Node.js as a background process.
Output:
Test access to the application using Curl on the host port 3000.
Output:
NVM (Node Version Manager) is a command-line tool for installing, managing, and switching between different Node.js versions. Follow the steps below to install NVM and run multiple Node.js versions:
Download the latest NVM installation script.
Run the script to install NVM.
Output:
Apply the NVM changes to your active shell environment.
List all Node.js versions available for download.
Output:
Install a specific Node.js version and NPM on your server. For example, Node.js version 22.5.1.
Output:
Install another Node.js version, such as 20.15.1.
Switch to a specific Node.js version. For instance, 22.5.1.
Output:
Install the latest Node.js LTS version on your server.
Install a specific LTS version such as lts/iron.
View the active Node.js version.
Output:
View the active NPM version.
Output:
You have installed Node.js and NPM on Debian 12. You installed multiple versions to enable the development of web applications that require a specific version. Node.js lets you to develop and deliver web applications with all necessary dependency packages using the Node Package Manager (NPM). For more information, visit the Node.js documentation.
0 Comments
Be the first to comment and share your perspective with the community.