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.
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.
To keep your system running with the latest software and security updates, always start with a system update. Run the following command:
sudo apt update && sudo apt upgrade -y
This ensures your system has the newest security patches and software versions before proceeding with the installation.
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:
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.
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:
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.
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.
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:
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:
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.
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:
- nodejs.org – Official website
- nodejs.org/en/docs – Node.js documentation
Do you have specific questions not answered here? Our team is available daily for further questions or support – don’t hesitate to contact us! 🙂