Teaching Research and Publishings Speaking Engagements Professional Development About Me

Server Setup Documents

Installing and Configuring PM2

Installing PM2

Install PM2 using the SSH tool from Google Cloud.

Use this command:

sudo npm install -g pm2

Configure PM2

Locate the app.js file and start it using PM2:

cd /var/www/apps/index
pm2 start app.js --name "index"

If you then run this commandit will list the active NodeJS processes:

pm2 list

We then need to tell PM2 to start app.js in startup:

pm2 startup systemd

This command will create some output and provide a command that needs to be run. Copy and paste this command and push enter. It will look something like this:

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u googleuser --hp /home/googleuser

You will need the following command to restart your NodeJS applications when developing:

pm2 restart index