Node.js: install Ubuntu 20.04.1
Sumber: https://linuxhint.com/install-nodejs-ubuntu-getting-started/
sudo su apt update apt install -y nodejs
cek
nodejs -v
install apps pendukung
apt -y install npm sudo npm install npm --global
cek
npm -v
Menggunakan Node.JS
Sebagai user biasa,
mkdir nodejsapp cd nodejsapp nano firstapp.js
isi
console.log('First NodeJS Application');
chmod +x firstapp.js
Membuat Web Server Local
cd ~/nodejsapp nano server.js
isi
var http = require('http'); var server = http.createServer(function(request, response) { resquest.writeHead(200,{'Content-Type': 'text/plain'}); response.end('NodeJS App'); }); server.listen(6060); console.log('Server is running at http://localhost:6060/');
chmod +x server.js
Jalankan dengan perintah,
nodejs server.js
Akses ke
http://localhost:6060
Membuat Web Server IP Ethernet
cd ~/nodejsapp nano server.js
isi
var http = require('http'); var server = http.createServer(function(request, response) { resquest.writeHead(200,{'Content-Type': 'text/plain'}); response.end('NodeJS App'); }); server.listen(6060,'192.168.0.171'); console.log('Server is running at http://localhost:6060/');
chmod +x server.js
Jalankan dengan perintah,
nodejs server.js
Akses ke
http://ip-ethernet:6060