Deploying the app using PM2 in EC2
sn17091004 opened this issue · 3 comments
Hi,
I am following this tutorial https://medium.com/@Keithweaver_/setting-up-mern-stack-on-aws-ec2-6dc599be4737
and trying to deploy this app.
However, I am stuck in this step pm2 start server.js -- --production
. It is throwing error but there is no description of error / logs.
Have anyone deployed this app to EC2 with PM2 ? Can you please help in deploying this app ?
Or is there anything wrong with this command pm2 start server.js -- --production
Thanks,
I just deployed on DigitalOcean droplet and this worked.
I reckon it should work for EC2 as well.
start:prod
script under packages.json
gave me some clues
"start:prod" : "cross-env NODE_ENV=production node index.js"
According to this we need to set environment as production and then run index.js
pm2 config and setup
Step 1:
cd
to project folder
Step 2: Create ecosystem.config.js
file for pm2
with the following config
module.exports = {
apps : [{
name : 'MERN',
script : 'index.js',
env: {
NODE_ENV: 'development'
},
env_production : {
NODE_ENV: 'production'
}
}],
};
Replace 'MERN' with your app's name so it will show in pm2 list.
Step 3: Start app's process using pm2
For production -
pm2 start --env production
For development -
pm2 start --env development
You should see following output
App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼──────┼───────────┼──────┼──────────┤
│ MERN │ 0 │ fork │ 29305 │ online │ 0 │ 3m │ 0.1% │ 93.4 MB │ root │ disabled │
Thats it! 👍 Your app is now up and running.
Hope this helps!
Please let me know how it goes.
Some basic pm2 operations / [ replace MERN with your app name]
Stop App
pm2 stop MERN
Start App
pm2 start MERN
Monitor App
pm2 monit MERN
Delete App
pm2 delete MERN
Show list of running pm2 processes
pm2 list
Hi,
Thanks for the response. Let me spin up an instance with all these changes and I will update if it worked. Once again, thanks.
Will close for the time being, feel free to reopen if there is still an issue related to the repo itself.