Skip to content

Instantly share code, notes, and snippets.

@Juriy
Last active May 31, 2020 15:22
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Juriy/b9536b98236f382ff4adb771073acc24 to your computer and use it in GitHub Desktop.
Save Juriy/b9536b98236f382ff4adb771073acc24 to your computer and use it in GitHub Desktop.

Deploying Node

This list of commands is based on my talk in Node.js Global Summit tested on Digital Ocean, CentOS 8.

Check out https://juriy.com for more links!

check out juriy.com for more links! This playlist describes the process in MUCH more details https://www.youtube.com/playlist?list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh

dnf -y install vim

# installing node
curl -sL https://rpm.nodesource.com/setup_14.x | bash -
dnf -y install nodejs

# create non-root user, always good idea
adduser juriy

# become that user
sudo su - juriy


# allow logging in with the same key as root uses (your key if it was Digital Ocean) 
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

# become root again
logout
cat ~/.ssh/authorized_keys >> /home/nanogram/.ssh/authorized_keys


# on your LOCAL environment, grab the code you want to run 
# (choose your files and folders)
tar czf app.tar.gz client server
scp app.tar.gz juriy@app.juriy.com:

# going back to the server, as non-root user 
# (assuming we are in home folder)
mkdir app
tar xf app.tar.gz -C app
cd app
npm i

# just check that app works, but don't leave it this way, 
# the process will halt once you log out!!!
npm start

# run following as root user
npm i -g pm2

# go back to your app as non-root user
pm2 start main.js

# save config, when server is restarted it will run your app automatically
pm2 save

# run below as root again
# this command will make sure that PM2 itself starts when the server is rebooted
pm2 startup -u juriy --hp /home/juriy

# install nginx
dnf install nginx

# start editing config, change for your domain
vim /etc/nginx/conf.d/beta.juriy.com.conf


Basic config looks like that:

server {
  listen       80;
  listen       [::]:80;
  server_name  beta.juriy.com;

  location / {
    proxy_pass "http://localhost:8080/";
  }
}

# important! NGINX will not be allowed to connect to NODE
# without this permission
setsebool -P httpd_can_network_connect on

# enable couple of repos required for the next tools to be installed
dnf install -y epel-release
dnf config-manager --set-enabled PowerTools

# get certbot
dnf install certbot python3-certbot-nginx

# let certbot do all the job of getting the certificate
certbot --nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment