Installing and using Node.js on a Linux server
Node.js is based on the V8 JavaScript engine, originally developed by Google for use in the Chrome browser. This engine compiles JavaScript into fast machine code, allowing Node.js to deliver very high performance when handling I/O-intensive tasks, such as processing network requests, file operations, or real-time communication.
The event-driven, non-blocking I/O model
The power of Node.js lies in its event-driven, non-blocking I/O model. Instead of executing each task synchronously and blocking — where the next task must wait until the previous one is completed — Node.js works asynchronously and processes tasks in parallel via callbacks, promises, or async/await. This makes Node.js particularly suitable for applications that must support many concurrent connections, such as chat applications, streaming services, or API gateways.History and governance
The project was officially released on May 27, 2009, by Ryan Dahl, the original author. Dahl introduced the idea of a server-side JavaScript runtime during a presentation at JSConf EU in Berlin in November 2009. During this demonstration, he showed how Node.js efficiently handled large numbers of concurrent connections. The first version only supported Linux and Mac OS X.In January 2010, npm (Node Package Manager) was introduced. Since then, npm has grown into the largest software package registry in the world, with more than a million open-source packages available to developers. Npm significantly simplified the development workflow and played a crucial role in the rapid growth of Node.js.
The development and maintenance of Node.js was supported by Joyent, a cloud software company that hired Ryan Dahl to further develop the project. In 2011, Node.js launched a native Windows version, the result of a collaboration between Microsoft and Joyent. Until then, Windows users could only run Node.js through emulation or virtual machines.
In 2015, the Node.js Foundation was established to manage further development, independent of a single commercial entity. In 2019, the JS Foundation and the Node.js Foundation merged into the OpenJS Foundation. Today, the development of Node.js falls under the management of the OpenJS Foundation.
Core modules and usage
The core modules of Node.js include functionality for creating HTTP servers, file operations (via the `fs` module), network protocols such as TCP and UDP, streams for efficient data transfer, and cryptographic functions for security. One of the most common applications is building RESTful APIs with frameworks such as Express.js, Koa, or Fastify. These frameworks build on top of Node.js's basic functionality and offer a structured way to manage routes, middleware, and error handling.Node.js is also the underlying technology behind numerous tools such as bundlers (Webpack, Vite), test frameworks (Jest, Vitest), and linters (ESLint). When automating tasks — build scripting — Node.js has become indispensable. By using JavaScript across the entire stack (both front-end and back-end), teams can work more efficiently and share code between different layers of their application.
In cloud-native development, Node.js plays an important role. Due to its low overhead and fast startup time, Node.js is a popular choice for serverless functions (such as AWS Lambda, Google Cloud Functions) and containerized applications (with Docker and Kubernetes). In combination with tools such as Docker Compose and Testcontainers, developers can set up local development and test environments that closely match production environments.
Installing Node.js on Ubuntu 22.04 or 24.04
The easiest way to install Node.js on Ubuntu is via the official NodeSource repository. This repository offers the latest stable versions.Step 1: Update system packages
First update the package list and install existing updates:sudo apt update && sudo apt upgrade -y
Step 2: Add the NodeSource repository
Add the NodeSource repository for Node.js 20 LTS (the current long-term support version):curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
For Node.js 22 (the latest release), replace `20.x` with `22.x`.
Step 3: Install Node.js
Install Node.js with apt:sudo apt install -y nodejs
Step 4: Check npm
Npm is automatically installed along with Node.js. Check the versions:node --version
npm --version
Step 5: Creating your first Node.js application
Create a simple HTTP server to test that everything works. Create a file `server.js`:nano server.js
Paste the following code:
const http = require('http');</p><p>const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Node.js works on this Pixzo server!\n');
});</p><p>server.listen(3000, () => {
console.log('Server running at http://localhost:3000');
});Save the file and close nano (Ctrl+O, Enter, Ctrl+X).
Step 6: Starting the server
Start the server:node server.js
Step 7: Testing the server
Open a second terminal and test the server with curl:curl http://localhost:3000
Step 8: Stopping the server
Stop the server with Ctrl+C in the terminal where it is running.Verification
Check whether the installation was performed correctly with these commands:node --version
npm --version
which node
which npmThe output shows the installed version numbers. For Node.js 20 LTS, you would expect, for example, `v20.11.0` or higher. The `which` commands confirm that the binaries are correctly installed in your PATH.
Frequently asked problems
Problem 1: "curl: command not found"
If curl is not installed, install it first:sudo apt install -y curl
Problem 2: Permission denied when installing global npm packages
Fix this by correcting the npm cache directory:mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Problem 3: Node.js version is too old after installation
If you have an older version than expected, remove the existing installation and reinstall via NodeSource:sudo apt remove -y nodejs npm
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejsNode.js continues to evolve under the management of the OpenJS Foundation, and the combination of high performance, a broad ecosystem, and strong community support makes it one of the most influential technologies in the world of open-source software, servers, hosting, networks, and containers — which version will soon be running on your Pixzo server?