Node.js is a Javascript runtime built on Chrome’s V8 Javascript engine. Node.js allows you to build many types of server-side applications quickly and easily.
With Node.js you can use your Javascript programming skills on a server environment. While NPM is the largest open source ecosystem in the world.
In today’s post we will show you how to install Node.js and npm on CentOS 7. Installation is pretty easy. You just follow the instructions as below.
Contents
Step 1: Prepare
You need to prepare the following:
- A brand new Linux server with CentOS 7 installed. This tutorial I made on Digital Ocean ‘s VPS (See discount code HERE ). You can refer to other VPS providers here.
- Connect to the server using an SSH Client like MobaXterm . Login with root user.
Step 2: Update the system and install the necessary software:
|
1
2
|
yum update –y
yum install curl nano
|
Step 3: Install Node.js and npm from NodeSource repository
We will install the Node.js 6 LTS from the NodeSource repository. Because NodeSource repository depends on EPEL repository. So you need to install the EPEL repository with the following command:
|
1
|
yum install epel–release
|
Then run the following command to install the NodeSource repository
|
1
|
curl —silent —location https://rpm.nodesource.com/setup_6.x | sudo bash –
|
Once the NodeSource is ready, you install Node.js and NPM with the following command:
|
1
|
yum install nodejs
|
After successful installation, you can check the version of Node.js with the command:
|
1
|
node –v
|
You will get the following output: v6.11.4
To check if npm install was successful, use the following command:
|
1
|
npm –v
|
You will get the following result: 3.10.10

Step 4: Check the settings again
If you want to know if Node.js is working OK or not, let’s create a test file:
|
1
|
nano hello_world.js
|
Then you add the following line of code: (remember to enter your ip address)
|
1
2
3
4
5
6
7
8
9
10
|
const http = require(‘http’);
const port = 3000;
const ip = ‘your_address_ip’;
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Hello World’);
}).listen(port, ip);
console.log(`server is running on ${ip}:${port}`);
|
Start the node web server with the following command:
|
1
|
node hello_world.js
|
You will get the result like below

Open your browser and go to http://your_ip_address:3000 , you will see “Hello World”.
That is all. You have learned how to install Node.js and npm on Centos 7.

