WWW.UIO.VN luôn có bộ phận thường trực sẵn sàng để hỗ trợ nhu cầu của bạn bất kỳ khi nào bạn phát sinh nhu cầu (24/7 kể cả ngày nghỉ lễ).

VietnamEnglish

WWW.UIO.VN

Thiết kế website doanh nghiệp siêu nhỏ -> nhỏ -> vừa | marketing online, thiết kế hình ảnh, infographic, video nhận diện thương hiệu doanh nghiệp, nhà hàng, khách sạn, cửa hàng, giải trí.

GmailYoutubeFacebookMessengerwhatsappZALOPHONEZALO

INSTALL NODEJS NVM, NPM AND PM2 TO RUN EXPRESS JS IN UBUNTU

Tags:

Sau khi cài đặt NVM (Node Version Manager/NeVerMind), chúng ta có thể dễ dàng cài đặt các phiên bản Node.js khác nhau và chọn phiên bản cần sử dụng cho ứng dụng của mình.

INSTALL NODEJS NVM, NPM AND PM2 TO RUN EXPRESS JS IN UBUNTU

Cài đặt NVM trên Ubuntu

Tải và cài đặt

Github: nvm-sh

Kiểm tra phiên bản nvm

1 nvm --version

Cài đặt Nodejs phiên bản 12

1nvm install 18.17.0

# check if installed

1nvm --version

==> 0.39.5

# list available Node.js versions

1nvm ls-remote

# choose one version and install it

# example of v10.4.1 installation

1node --version

==> v12.16.2

Khai báo dùng phiên bản nodejs cho nvm

1nvm use 12.16.22nvm alias default 18.17.0

# check more nvm usage

1nvm --help

PM2 Cài đặt Process Manager 2

1npm install pm2@latest -g ;

# check if installed properly

1pm2 -V

# start our server with PM2 after instal Express js

1pm2 start server.js2pm2 startup

# this will generate another command that you need to run

# We also need to save what processes

# should get started with pm2

1pm2 save

#To restart an application:

1pm2 restart 02pm2 restart all

#To stop a specified application:

pm2 stop api

pm2 stop

#To stop and delete an application:

pm2 delete api

pm2 delete all

#To list all running applications:

pm2 list

# Or

pm2

#To reset the restart counter:

pm2 reset all

Cài Express Js

# go to your user's directory

cd /home/lukas

# create folder simpleServer

mkdir simpleServer

# go inside

cd simpleServer

# create package.json

npm init -y

# install Express.js

npm install express

# open nano

nano server.js

# to save, press Ctrl + X ==> Y ==> Enter

--------------------------

1const express = require('express');2const app = express();3app.get('/', (req, res) => {4 res.send("Hello World!");5});6const port = 3000;7const server = app.listen(port, () => {8 console.log(`Listening on http://localhost:${port}`);9});

--------------------------

Cài Nginx web server proxy

sudo apt-get install nginx

cd /etc/nginx/sites-available

sudo nano simpleServer

--------------------------

server {

listen 80;

server_name www.example.com example.com;

location / {

proxy_pass http://localhost:3000/;

}

}

--------------------------

# check if your configuration is ok

sudo nginx -t

# enable your configuration

sudo ln -s /etc/nginx/sites-available/simpleServer /etc/nginx/sites-enabled

# restart nginx

sudo service restart nginx

Nguồn:

Nguồn

LIÊN HỆ

Để lại thông tin của bạn và chúng tôi tiếp nhận liên hệ tư vấn theo yêu cầu.

sending
+

WWW.UIO.VN

CALLZALOscroll to tOP