For Ubuntu
- Configure Server
- Update packages/Install Node/NPM
- Clone your project from GitHub
- Install project dependencies and test app
- Setup PM2 to keep your app running
- Setup firewall
- Install/Configure NGINX
- Connect Domain to Server (if applicable)
- Add SSL using Let's Encrypt
- All done!
- copy the static ip address
- In a terminal, login to the server like so:
# SSH into root machine
ssh root@ipAddress- Dismiss any warnings, then clear the terminal
clear- First, update any outdated packages
sudo apt update- Install Node/NPM
# Install Node
sudo apt install nodejs
# Confirm Node installed correctly
nodejs -v
# Install NPM
sudo apt install npm
# Verify installed version
npm -v- The installed Node version is likely outdated, but you can update by intalling NVM (Node Version Manager)
# Install cURL
sudo apt install curl
# Install NVM
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
# Load the NVM login script
source ~/.bashrc
# Install desired Node version
nvm install 16.16.0
# Tell NVM which Node version to use
nvm use 16.16.0- First create a webServicesfolder on the server and navigate to that folder
mkdir webServices && cd webServices- Next, clone your git repository into the /webServicesfolder
git clone myProject.git- If prompted for a password, you may need a Personal Access Token. If using GitHub, follow this guide.
cd myProject
npm install # install project dependencies
npm start # start the project
# stop app
ctrl+C- Install and initialize PM2:
npm install pm2@latest -g
pm2 start app.js # replace "app.js" with your entry point- Other PM2 Commands:
- pm2 status: get the status of your app
- pm2 list: list all processes
- pm2 monit: monitor all processes launched by PM2
- pm2 restart app.js: restart your app
- pm2 stop app.js: stop your app
- pm2 logs: view any- console.logs()generated by your app- pm2 flush: flush any logs from the pm2 console
 
 
- Configure PM2 to start on server reboot:
pm2 startup- To remove the startup script, run:
pm2 unstartup- Reboot the server for changes to take effect:
reboot- Confirm that PM2 is running:
pm2 status- Check status of firewall:
ufw status- Enable firewall:
ufw enable- Enable SSH with firewall:
ufw allow ssh- Check firewall status again:
ufw status- Allow HTTP through port 80:
ufw allow http- Allow HTTPS through port 443:
ufw allow https- Check firewall one more time:
ufw status- Install NGINX:
sudo apt install nginx- Open the NGINX config file:
sudo nano /etc/nginx/sites-available/default- Edit the NGINX config file:
# /etc/nginx/sites-available/default
server {
  ...
  #server_name _; #if not using a custom domain
  server_name your_domain.com www.your_domain.com; #if using a custom domain
  ...
  location / {
          # First attempt to serve request as file, then
          # as directory, then fall back to displaying a 404
          proxy_pass http://localhost:5000; #whatever port your app runs on
          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;
  }
}- If running a GraphQL server, you may want to add the following:
# /etc/nginx/sites-available/default
server {
    ...
    location /graphql {
        proxy_pass http://localhost:4000/graphql;
    }
    ...
}- Save the NGINX config file:
# Write out the file
ctrl+O
# Do not modify filename
return/enter- Exit nano:
# Exit nano
ctrl+X- Confirm changes were saved successfully:
sudo nginx -t- Restart NGINX service:
sudo service nginx restart- Open a web browser to the server's IP Address (or domain, if applicable) and confirm the Node app loads as expected.
Coming soon.
- Add the PPA:
sudo add-apt-repository ppa:certbot/certbot- Run any necessary updates:
sudo apt update- Install python-certbot-nginx:
sudo apt-get install python-certbot-nginx- Add certbot to the app domain:
sudo certbot --nginxIf certbot asks to redirect all requests to HTTPS, you may choose that option.
- Test the SSL renewal process (SSL certificate is only valid for 90 days):
certbot renew --dry-run