Deploying Nodejs pm2 to Ubuntu 20.0

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
cd ~
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install -y nodejs
sudo apt install -y build-essential
sudo apt install -y yarn
sudo yarn global add pm2
sudo apt update
cd ~
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install -y nodejs
sudo apt install -y build-essential
sudo npm install pm2@latest -g
sudo npm install yarn -g
sudo apt install nginx
sudo git clone https://gitlab.com/USERNAME/YOUR_REPO.git
cd YOUR_REPO
sudo yarn
NODE_ENV=test
PROJECT_JWT_SECRET=top_secret
APPLICATION_DEBUG=false
PORT=3000
DATABASE_USERNAME=USERNAME
DATABASE_PASSWORD=PASSWORD
DATABASE_HOST=IP_OR_DOMAIN
DATABASE_PORT=PORT
DATABASE_NAME=DB_NAME
DATABASE_ENGINE=mysql
MAIL_HOST=mail.domain.my
MAIL_USERNAME=noreply@domain.my
MAIL_PASSWORD=passwordsadasd
MAIL_PORT=465
sudo pm2 start app.js --name=myapp
curl localhost:3000
sudo nano /etc/nginx/sites-available/myapp
server {
listen 80;
listen [::]:80;
index index.html index.htm index.nginx-debian.html;
server_name ip;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enable/
sudo nginx -t
sudo systemctl reload nginx
sudo nano /etc/nginx/sites-available/myapp
sudo nginx -t
sudo systemctl reload nginx
sudo ufw enable
sudo ufw allow ‘Nginx Full’
sudo ufw allow OpenSSH
sudo ufw reload
sudo apt install certbot python3-certbot-nginx
sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
sudo ufw reload
sudo certbot --nginx -d example.com

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store