[ nodejs ] pm2 : node package restart tool

Installation

npm i -g pm2
npm i -g babel-cli ( for --intepreter babel-node option )

run 

Example:

node -r dotenv/config ./node_modules/.bin/react-scripts start dotenv_config_path=.env.production

in pm2

pm2 start --node-args="-r dotenv/config" node_modules/react-scripts/bin/react-scripts.js --name app --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' -- start dotenv_config_path=.env.$NODE_ENV

Example2:

NODE_ENV=development node ./dist/server.js

in pm2

NODE_ENV=$NODE_ENV pm2 start --name api --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' ./dist/server.js

Example3:

nodemon ./src/server.js --exec babel-node

in pm2

NODE_ENV=$NODE_ENV pm2 start --name crontab --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' --interpreter babel-node ./src/server.js

list all apps

pm2 list

kill all apps

pm2 kill

View log in real-time

pm2 logs api

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s