Node.js: install Ubuntu 20.04.1: Difference between revisions
From OnnoCenterWiki
Jump to navigationJump to search
Onnowpurbo (talk | contribs) No edit summary |
Onnowpurbo (talk | contribs) No edit summary |
||
| Line 5: | Line 5: | ||
apt update | apt update | ||
apt install -y nodejs | apt install -y nodejs | ||
cek | cek | ||
nodejs -v | nodejs -v | ||
| Line 14: | Line 12: | ||
apt -y install npm | apt -y install npm | ||
sudo npm install npm --global | 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://ip-server:6060 | |||
Revision as of 02:39, 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');
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://ip-server:6060