Learn how to install Nodejs on CentOS 8 with this comprehensive guide. Step-by-step instructions to set up a Nodejs server, ensuring a smooth installation process for your Linux environment. #centlinux #linux #nodejs
Table of Contents
What is Nodejs?
Nodejs is a powerful and versatile runtime environment that allows developers to execute JavaScript code outside of a web browser. This opens up a wide array of possibilities for server-side development, enabling the creation of dynamic and interactive web applications. Key features of Node.js include:
- Asynchronous and Event-Driven: Node.js is designed around an event-driven, non-blocking I/O model. This means that operations, such as reading from the network or filesystem, do not block the execution of the program, allowing it to handle multiple operations concurrently. This makes Nodejs particularly efficient and scalable for real-time applications.
- Single Programming Language: By using JavaScript for both client-side and server-side code, Nodejs simplifies the development process. Developers can work in a single language across the entire application stack, improving code consistency and reducing the learning curve.
- Rich Ecosystem: The Node Package Manager (npm) is one of the largest ecosystems of open-source libraries and modules available for any programming language. With npm, developers can easily find and integrate third-party packages into their applications, speeding up development and enabling code reuse.
- High Performance: Built on the V8 JavaScript engine, Nodejs is highly optimized for performance. It compiles JavaScript directly to machine code, allowing for fast and efficient execution of scripts.
- Community and Support: Nodejs has a large and active community that contributes to its growth and improvement. There are numerous resources, tutorials, and forums available to help developers learn and troubleshoot.
- Cross-Platform Compatibility: Node.js runs on various platforms, including Windows, Linux, and macOS, making it a flexible choice for development teams working in diverse environments.
- Microservices and API Development: Node.js is well-suited for building microservices and RESTful APIs. Its lightweight nature and ability to handle asynchronous operations make it an ideal choice for services that need to handle numerous simultaneous requests efficiently.
Read Also: How to install Nodejs in Docker
In summary, Nodejs is a robust runtime environment that leverages JavaScript’s capabilities on the server side, offering high performance, scalability, and a vast ecosystem of modules and libraries. It is a popular choice for developers looking to build modern, efficient, and scalable web applications.
Node.js is written in C, C++ and JavaScript. It is distributed under MIT License and can be download from their official website or Node.js Github Repository.

What is Nodejs used for?
Nodejs is used for a wide range of applications due to its efficiency and versatility. Some of the most common use cases include:
- Web Servers: Nodejs is frequently used to build web servers that can handle HTTP requests and serve dynamic content. Its non-blocking I/O model allows it to efficiently manage multiple simultaneous connections.
- API Development: Nodejs is ideal for building RESTful APIs and microservices. Its asynchronous nature helps in handling numerous API requests simultaneously without performance degradation.
- Real-Time Applications: Nodejs excels in developing real-time applications such as chat applications, online gaming, live streaming services, and collaborative tools. Its event-driven architecture is perfect for applications that require real-time interaction.
- Single-Page Applications (SPAs): With Nodejs, developers can build SPAs where the server handles the logic, while the client side renders the content dynamically. This approach enhances the user experience by reducing load times and providing seamless interaction.
- Internet of Things (IoT): Nodejs is used in IoT projects for collecting and processing data from various devices. Its ability to handle numerous concurrent connections makes it suitable for managing communications between devices in real-time.
- Server-Side Rendering (SSR): Node.js can be used for server-side rendering of web pages, which improves the performance and SEO of web applications. Frameworks like Next.js leverage Node.js for this purpose.
- Microservices Architecture: Node.js supports the development of microservices, allowing developers to build and deploy small, independently running services. This modular approach simplifies scaling and maintenance.
- Command Line Tools: Developers use Nodejs to create command-line tools and utilities. Its package manager, npm, makes it easy to publish and distribute these tools.
- Data Streaming Applications: Node.js handles data streams efficiently, making it suitable for applications that process real-time data streams, such as video streaming services and file uploading platforms.
- Proxies and Load Balancers: Nodejs can act as a proxy server to handle requests to other servers, load balancing, or even caching data to improve performance.
- Cross-Platform Desktop Applications: Tools like Electron use Nodejs to build cross-platform desktop applications with web technologies, enabling developers to create applications that run on Windows, macOS, and Linux.
- Automation and Scripting: Nodejs is used for writing scripts to automate repetitive tasks, manage system operations, and streamline workflows.
In summary, Nodejs is a versatile tool used in web development, real-time applications, IoT, microservices, and more. Its event-driven, non-blocking architecture makes it suitable for applications requiring high performance and scalability.
Recommended Training: Angular & NodeJS – The MEAN Stack Guide [2025 Edition] from Maximilian Schwarzmüller

Node.js vs Express.js
Nodejs and Express.js are related but serve different purposes in web development:
Nodejs
- Nodejs is a runtime environment that allows developers to run JavaScript code on the server side.
- It provides a platform for building scalable and efficient network applications using JavaScript.
- Node.js includes libraries and tools for handling HTTP requests, file system operations, and other server-side tasks.
- It has a non-blocking, event-driven architecture, making it well-suited for real-time applications and handling concurrent connections efficiently.
Express.js
- Express.js is a web application framework for Node.js, built on top of it.
- It provides a set of features and utilities for building web applications and APIs more easily and efficiently.
- Express.js simplifies common tasks such as routing, middleware integration, and handling HTTP requests and responses.
- It follows a minimalist design philosophy, allowing developers to add only the features they need, making it flexible and lightweight.
- Express.js is widely used in the Node.js ecosystem and is known for its simplicity, performance, and robustness.
In essence, Node.js is the runtime environment that allows JavaScript to run on the server side, while Express.js is a framework that simplifies and streamlines the process of building web applications and APIs using Node.js. Developers often use them together to create powerful and scalable server-side applications with JavaScript.
Read Also: How to install OpenAI on Rocky Linux 9
Nodejs Server Specification
We have provisioned a minimal CentOS 8 KVM machine with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – CentOS 8.2
- Hostname – nodejs-01.centlinux.com
- IP Address – 192.168.116.230 /24
Charger for Lenov Laptop Computer 65W 45W Round Tip Power Supply AC Adapter for Lenovo IdeaPad 330-14, 330-15, 330-17, 510-15, 330s-14, 330s-15 Lenovo Flex 6-14 Laptop Charger
$9.90 (as of March 7, 2025 18:54 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Update Linux Operating System
Connect with nodejs-01.centlinux.com as root user by using a ssh client.
As per the best practice, update your installed software packages on Linux operating system by using dnf command.
# dnf update -y
Last metadata expiration check: 0:00:20 ago on Wed 18 Nov 2020 09:43:56 PM PKT.
Dependencies resolved.
Nothing to do.
Complete!
Our operating system is already up-to-date. Therefore, no package was updated. The output may vary on your Linux server.
Verify the Linux operating system and Kernel version that are being used in this installation guide.
# uname -r
4.18.0-193.28.1.el8_2.x86_64
# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
Install Nodejs Server on CentOS 8
There can be two ways to install Nodejs on CentOS 8. According to your requirement, you can follow any one of these methods.
1. Install Nodejs from Yum Repo
The easiest method to install Nodejs on CentOS 8 is by using the Linux yum repository.
In CentOS 8 yum repositories, the two stable versions of the Nodejs are already available. These are the most commonly used versions and may work in most situations.
To get a list of available versions of Nodejs in Linux yum repository, you can use following dnf command.
# dnf module list nodejs
Last metadata expiration check: 0:07:05 ago on Wed 18 Nov 2020 09:43:56 PM PKT.
CentOS-8 - AppStream
Name Stream Profiles Summary
nodejs 10 [d] common [d], development, minimal, s2i Javascript runtime
nodejs 12 common [d], development, minimal, s2i Javascript runtime
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
Install your required version of Nodejs using dnf command, we are installing the version 12 on our Linux server.
# dnf module install -y nodejs:12...
Installed:
nodejs-1:12.18.4-2.module_el8.2.0+530+cb1b9c8b.x86_64
nodejs-docs-1:12.18.4-2.module_el8.2.0+530+cb1b9c8b.noarch
nodejs-full-i18n-1:12.18.4-2.module_el8.2.0+530+cb1b9c8b.x86_64
npm-1:6.14.6-1.12.18.4.2.module_el8.2.0+530+cb1b9c8b.x86_64
Complete!
After successful installation, check the version of Nodejs and Node Package Manager (NPM) versions.
# node -v
v12.18.4
# npm -v
6.14.6
Hyperkin DuchesS Wired Controller with Hall Effect Sticks – Officially licensed S Controller replica for Xbox Series X|S, Xbox One, Windows 10|11, PC , 3.5MM, Audio Jack, Impulse Triggers, Plug and Play, Gaming Gamepad Black
$44.99 (as of March 6, 2025 19:40 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)2. Install Nodejs using NVM
Although it is quiet convenient to install Node.js from Linux yum repository. But you may not found the latest versions of Node.js therein.
For Example, Nodejs version 14 LTS and 15 are already released, but they are not available in Linux yum repository.
Therefore, if you wish to install latest version of Nodejs then you have to use the Node Version Manager (NVM).
By using NVM you can easily install/ uninstall different versions of Nodejs on/from your Linux server.
NVM is available at GitHub. You can see complete project details at NVM Github repository.
You can install NVM by using the script provided in the NVM documentation.
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13527 100 13527 0 0 7056 0 0:00:01 0:00:01 --:--:-- 7052
=> Downloading nvm as script to '/root/.nvm'
=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> 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
NVM has been installed, you can now use nvm command it to install Nodejs on your Linux server.
But first, list down the available versions of Nodejs.
# nvm list-remote
...
v14.14.0
v14.15.0 (LTS: Fermium)
v14.15.1 (Latest LTS: Fermium)
v15.0.0
...
Although, Node.js v15 is available, but it is a better approach to install the LTS (Long Term Support) version especially if your are installing Nodejs on a production machine.
You can install the latest LTS version of Nodejs by using nvm command.
# nvm install --lts
Installing latest LTS version.
Downloading and installing node v14.15.1...
Downloading https://nodejs.org/dist/v14.15.1/node-v14.15.1-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.15.1 (npm v6.14.8)
Creating default alias: default -> lts/* (-> v14.15.1)
Verify the installed versions of Node.js and Node Package Manager (NPM).
# node -v
v14.15.1
# npm -v
6.14.8
Similarly, you can switch to another version of Node.js by using the NVM as follows.
# nvm install v13.6.0
Downloading and installing node v13.6.0...
Downloading https://nodejs.org/dist/v13.6.0/node-v13.6.0-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v13.6.0 (npm v6.13.4)
Again check the installed versions of Node.js and NPM.
# node -v
v13.6.0
# npm -v
6.13.4
Create & Deploy a Simple Nodejs Application
You can test your Nodejs server by writing a simple JavaScript.
Create a text file in vim editor.
# vi Node.js_test.js
Add following lines of code in this file.
const http = require('http');
const port = 9000;
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
});
server.listen(port, () => {
console.log(`Server running at http://your-ip-address:${port}/`);
});
Temporarily allow the service port 9000/tcp in Linux firewall.
# firewall-cmd --add-port=9000/tcp
success
Start a Nodejs debugger process by using following command.
# node --inspect Node.js_test.js
Debugger listening on ws://127.0.0.1:9229/d25c2fe9-b50e-4bfb-aa45-1d6988d5d470
For help, see: https://nodejs.org/en/docs/inspector
Server running at http://your-ip-address:9000/
Use a web browser or following Linux command to test your Nodejs application.
# curl http://nodejs-01.centlinux.com:9000
Hello World
The Embedded Linux Security Handbook: Fortify your embedded Linux systems from design to deployment
$31.99 (as of March 7, 2025 18:51 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Final Thoughts
Setting up a Nodejs server on CentOS 8 can significantly enhance your web development projects by providing a robust and efficient environment. Following the steps outlined in this guide will ensure a smooth installation process.
Your Linux servers deserve expert care! I provide reliable management and optimization services tailored to your needs. Discover how I can help on Fiverr!
Leave a Reply
You must be logged in to post a comment.