Node.js: install Ubuntu 20.04.1: Difference between revisions
From OnnoCenterWiki
Jump to navigationJump to search
Onnowpurbo (talk | contribs) Created page with "Sumber: https://linuxhint.com/install-nodejs-ubuntu-getting-started/ sudo su apt update apt install -y nodejs ==Referensi== * https://linuxhint.com/install-nodejs-u..." |
Onnowpurbo (talk | contribs) |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
apt update | apt update | ||
apt install -y nodejs | 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'); | |||
http.createServer(function (request, response) { | |||
response.writeHead(200, {'Content-Type': 'text/plain'}); | |||
response.end('Server started\n'); | |||
}).listen(6060); | |||
console.log('Server 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== | |||
Referensi: https://stackoverflow.com/questions/17508815/node-js-referenceerror/17509537 | |||
cd ~/nodejsapp | |||
nano server.js | |||
isi | |||
var http = require('http'); | |||
http.createServer(function (request, response) { | |||
response.writeHead(200, {'Content-Type': 'text/plain'}); | |||
response.end('Node.JS Apps\n'); | |||
}).listen(6060,'0.0.0.0'); | |||
console.log('Server running at http://0.0.0.0:6060/'); | |||
chmod +x server.js | |||
Jalankan dengan perintah, | |||
nodejs server.js | |||
Akses ke | |||
http://ip-ethernet:6060 | |||
==Referensi== | ==Referensi== | ||
Latest revision as of 03:58, 2 November 2020
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');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Server started\n');
}).listen(6060);
console.log('Server 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
Referensi: https://stackoverflow.com/questions/17508815/node-js-referenceerror/17509537
cd ~/nodejsapp nano server.js
isi
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Node.JS Apps\n');
}).listen(6060,'0.0.0.0');
console.log('Server running at http://0.0.0.0:6060/');
chmod +x server.js
Jalankan dengan perintah,
nodejs server.js
Akses ke
http://ip-ethernet:6060