Skip to content

Setting up a production server

Özgün Babur edited this page Jul 25, 2022 · 10 revisions

Setting up a production server for CausalPath Newt webserver

This document describes how CausalPath webserver can be run in a production environment using PM2 and Nginx.

Prerequisites

Follow the guidelines in the README to download and run the app in the environment that the server will be hosted.

These instructions are tested on a VM with Ubuntu 20.04.

Assuming the server code is checked out to

/home/sammy/Code/causalpath-newt-webserver

and it is your current directory. sammy is your username.

You have node version 14 installed under

/home/sammy/.nvm

The server runs fine with the below command

npm start

Now, stop the server with Ctrl+C and follow the below steps.

Step 1. Install PM2

npm install pm2@latest -g

Step 2. Run the app with PM2

pm2 start npm --name CausalPath -- start

Make sure the server is running without problems after this command.

Step 3. Save the PM2 current state

pm2 save

Step 4. Make PM2 a service.

Type

pm2 startup systemd

This will print a message on the shell similar to the below.

[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/home/sammy/.nvm/versions/node/v14.20.0/bin /home/sammy/.nvm/versions/node/v14.20.0/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy

Copy and paste the last line (it will have your user name instead of sammy, and maybe other differences) on the shell.

sudo env PATH=$PATH:/home/sammy/.nvm/versions/node/v14.20.0/bin /home/sammy/.nvm/versions/node/v14.20.0/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy

Step 5. Install Nginx

sudo apt update
sudo apt install nginx
Clone this wiki locally