Installing pm2

To install pm2, run the following:

$ yarn global add pm2

Adding to a repo and starting the pm2 process:

In order to run the application in pm2 demon process, do the following for each applications as and when required.

Note

Below codes should be run from the application folder where package.json resides.

For nextjs

$ pm2 start yarn --name "nextjs" --interpreter bash -- start
$ pm2 startup # It will enable pm2 to startup automatically when server restarts
$ pm2 show nextjs #to check the status.

For Gatsby

First, you'll have to install gatsby-cli

$ npm i -g gatsby-cli

After that, start the pm2 demon process for Gatsby

$ pm2 start gatsby --name "gatsby" --interpreter bash -- serve
$ pm2 startup # It will enable pm2 to startup automatically when server restarts
$ pm2 show nextjs #to check the status.

Note

While running the pm2 start nextjs you will get an error because you haven't run the build as of yet. Either run npm build or yarn build > in order to build the production

Stopping the pm2 demon process

In order to run the application after pushing the code to the github:

$ pm2 stop nextjs #[whatever the name of the app]
$ yarn build
$ pm2 start nextjs

Last Updated: