Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying the app using PM2 in EC2 #394

Closed
sn17091004 opened this issue Aug 29, 2018 · 3 comments
Closed

Deploying the app using PM2 in EC2 #394

sn17091004 opened this issue Aug 29, 2018 · 3 comments

Comments

@sn17091004
Copy link

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,

@9gaurav
Copy link

9gaurav commented Sep 5, 2018

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

@sn17091004
Copy link
Author

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.

@mannyhenri
Copy link
Contributor

Will close for the time being, feel free to reopen if there is still an issue related to the repo itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants