On my EC2 I am deploying 2 nodejs apps.
What I am doing before is creating a multiple screen and run the npm run start.
Now I am trying to use the PM2, I installed it inside the ec2 and tried the following start command:
pm2 start --name "APP_NAME" npm -- start
The process runs but i do not think it was what im expecting. here is my run script inside package.json
"start": "env-cmd -f ./config/app.env node index.js"
I also tried adding adding pm2 start inside the package.json but fails as expected.
This is my first time trying the PM2 so I'm quite lost right now. Thanks in advance.
first create a file ecosystem.config.js:
module.exports = {
apps : [
{
name: "myapp",
script: "./app.js",
watch: true,
env: {
"PORT": 3000,
"NODE_ENV": "development"
},
env_production: {
"PORT": 80,
"NODE_ENV": "production",
}
}
]
}
after that you can run it like this :
pm2 start ecosystem.conf.js
for handling the logs :
npm i pm2-logrotate
or
pm2 install pm2-logrotate
after that you have to add pm2 as a service in your host.
pm2 startup
after all the configuration and checking the pm2 apps with :
pm2 status <instance number>
pm2 logs
you can save your current configuration in pm2 with :
pm2 save
more details about pm2 startup