Difference between revisions of "Node.js: install Ubuntu 20.04.1"

From OnnoWiki
Jump to navigation Jump to search
 
(6 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
 
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');
 +
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 10: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

Referensi

Pranala Menarik