Install Node.js on CentOS 7

Install Node.js dan NPM pada centos 7

  • Tambahkan repository nodesource
curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
  • Install Node.js dan NPM
yum install nodejs -y
  • Cek versi node.js dan npm
node -v
v10.24.1

npm -v
6.14.12

  • Jika ada error saat installasi Node.js, error seperti berikut:
[Errno 14] HTTP/HTTPS Error 404
[Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 403"
[Errno 14] Error 60 - It was impossible to connect to the CentOS servers
  • Lakukan clear cache system dan lakukan update repository fast
yum clean all && yum makecache fast

  • Tes aplikasi node.js dengan buat file hello.js (nano hello.js)
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, '0.0.0.0');
console.log('Server running at http://0.0.0.0:8080/');
  • Jalankan aplikasi hello.js
node hello.js
Server running at http://0.0.0.0:8080/
  • Test dengan curl pada new terminal atau browser
curl http://localhost:8080

Hello World

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.