Installing Node.js on a CentOS VPS
Node.js is a JavaScript-based platform for building lightweight and scalable web applications. Installing Node.js on a CentOS server can be a bit tricky, but following this guide, you’ll easily accomplish this task.
Step 1: System Update
Before installing Node.js, it’s recommended to update your system. Enter the following command in your terminal:
yum update
Step 2: Installing Node.js
To install Node.js on your CentOS server, follow these steps:
1. Install the EPEL repository using the command:
yum install epel-release
2. Install Node.js using yum:
yum install nodejs
Step 3: Verifying the Installation
To verify that Node.js is successfully installed, enter the command:
node -v
If you see the Node.js version, the installation was successful.
Step 4: Installing npm
npm (Node Package Manager) is the package manager for Node.js. Install npm using the command:
yum install npm
Step 5: Creating a Simple Node.js Application
Now you can create a simple Node.js application to ensure everything is working correctly. Create a file named index.js
with the following content:
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(3000, 'localhost');
console.log('Server running at http://localhost:3000/');
Run the application by entering the command:
node index.js
Open your browser and navigate to http://localhost:3000/ to see «Hello World» on the screen.
Conclusion
Now you know how to install Node.js on a CentOS VPS. This will allow you to develop and run your own web applications on your server. Happy coding!