Monday, October 3, 2016

Install latest Node.js on CentOS 7

Add Node.js Yum Repository:

# curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -

Install Node.js and NPM:

# yum install nodejs

Check Node.js version:

# node -v

v6.7.0

Check NPM version:

# npm -v

3.10.3

Create Demo Web Server:

# vim demo_srv.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Welcome Node.js');
}).listen(3001, "127.0.0.1");

console.log('Server running at http://127.0.0.1:3001/');

Start the web server:

# node --debug demo_server.js

Reference:

https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora

http://tecadmin.net/install-latest-nodejs-and-npm-on-centos/

No comments: