Express + Nginx

This show what commands to use to setup express app with nginx (I use this because I tend to forget the commands)

First choose a host (I recommend Digital Ocean)

Update Ubuntu (The OS I will be using)

$ sudo apt update
$ sudo apt upgrade

Create Project

$ mkdir app
$ cd app
$ git init

Install Node.js

$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt-get install -y nodejs
$ node --version

Install PM2

$ npm install pm2 -g

Create app

$ npm install express
$ nano app.js
app.js
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))

Use "CTRL + X" to exit nano editor

$ pm2 start app.js

Open ports

$ sudo ufw enable
$ sudo ufw status
$ sudo ufw allow ssh
$ sudo ufw allow http
$ sudo ufw allow https

Install Nginx

$ sudo apt install nginx
$ sudo nano /etc/nginx/sites-available/default

Add to server block

default
server_name beta.andre.gg;
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;
}

Last steps

$ sudo nginx -t
$ sudo service nginx restart

SSL