Skip to content

Setting Up Node.js on a Linux Server – Launch Modern JavaScript Applications

Discover how to set up a stable Node.js environment for scalable real-time applications using Docker and system preparation → Learn more now

12 November 20263 min read17 Views0 helpful

Introduction

Node.js is a cross-platform, open-source JavaScript runtime environment that executes JavaScript code outside the browser, for example on servers or in command-line tools. Based on the V8 engine, it supports asynchronous, event-driven I/O, making it extremely efficient for building scalable network and real-time applications.

The “JavaScript everywhere” paradigm allows developers to use a single language for both backend and frontend.

Preparation

Before setting up Node.js, you should prepare your system. This includes updating your operating system to the latest version and installing all necessary dependencies. This preparation ensures a stable environment and helps avoid issues during or after installation.

Update System

To keep your system running with the latest software and security updates, always start with a system update. Run the following command:

Code
sudo apt update && sudo apt upgrade -y

This ensures your system has the newest security patches and software versions before proceeding with the installation.

Install Dependencies

After the update is complete, you can proceed with installing dependencies. Node.js will run on your system in multiple Docker containers. Therefore, Docker must be installed first. Run the following commands:

Code
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

For a detailed step-by-step guide on installing and using Docker, see our Docker tutorial.

Installation

Once all prerequisites are met and preparations are complete, you can start installing the Node.js application.

To use Node.js in an isolated environment, first download the official Alpine-based image. Run the following command to pull the latest Node.js 22 image to your system and prepare it for container deployments:

Code
docker pull node:22-alpine

Then you can start a container based on this image and open a shell session inside it. Use the following command to start the container interactively. The --rm option ensures the container is automatically removed when you exit, keeping your host clean.

Code
docker run -it --rm --entrypoint sh node:22-alpine

Inside the container, check the installed Node.js version with node -v, which should display v22.19.0. Check the npm version with npm -v, expected to be 10.9.3. This confirms the image provides the correct versions of Node.js and npm and is ready to use immediately.

Configuration

After starting the Node.js container, it is recommended to configure important Node.js settings directly in the environment. A common approach is setting environment variables, for example:

Code
export NODE_ENV=production

This activates production mode, enables performance optimizations, and adjusts logging. For development purposes, you can set NODE_ENV=development to enable detailed error messages and debugging features.

A well-structured project folder is important, starting with a configuration file you create using the following command:

Code
npm init -y

This generates a package.json file that defines dependencies, scripts, and metadata for your project. It is the central configuration file for every Node.js application.

You can then install dependencies with npm install <package>, while development dependencies are added with npm install <package> --save-dev. The scripts section in package.json allows you to define custom commands like npm start or npm run build to simplify execution and project management.

For advanced setups, Node.js can be customized with .npmrc or .nvmrc files to enforce private registries, cache options, or a specific Node.js version. This ensures your application runs consistently across different environments.

Completion and Further Resources

Congratulations! You have now successfully installed and configured Node.js on your VPS/Dedicated Server. We also recommend checking out the following resources that can help you with server configuration:

Do you have specific questions not answered here? Our team is available daily for further questions or support – don’t hesitate to contact us! 🙂

FAQ

Frequently asked questions

First, update your system with sudo apt update && sudo apt upgrade -y. Since Node.js runs in multiple Docker containers, you then need to install Docker as a dependency.
Node.js is a cross-platform, open-source JavaScript runtime that executes JavaScript outside the browser, based on the V8 engine with asynchronous, event-driven I/O.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 Users found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.