Question

Nodejs app doesn't run with pm2

Hey, My Pm2 works fine but my web app won’t run. Then when I check the pm2 report, I get errored on status for both PM2 list and daemon logs. I am using pm2 version 3.2.2 and node version 8.0.0.

the code I run is pm2 start src/index.js and it is a react web app

How can I solve this?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hello,

What are the exact errors that you get?

Also if you have not already checked the pm2 logs, I would recommend checking your pm2 logs with this command:

pm2 logs

If you are unsure, you could share the logs here so I could advise you further.

If there are no errors, then the problem might be with your application.

Also, as a side note here is also a quick video on how to deploy Node.js with PM2, Nginx as a reverse proxy, and Cloudflare for SSL termination:

Regards, Bobby

In my situation, I also met pm2 errored:

internal/modules/cjs/loader.js:1068
  throw err;
  ^

Error: Cannot find module './config'
Require stack:
- /usr/my/express/js/app.js
- /usr/my/express/js/bin/www
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1065:15)
    at Function.Module._load (internal/modules/cjs/loader.js:911:27)
    at Module.require (internal/modules/cjs/loader.js:1125:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.<anonymous> (/usr/my/express/js/app.js:9:16)
    at Module._compile (internal/modules/cjs/loader.js:1236:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)
    at Module.load (internal/modules/cjs/loader.js:1085:32)
    at Function.Module._load (internal/modules/cjs/loader.js:950:14)
    at Module.require (internal/modules/cjs/loader.js:1125:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/my/express/js/app.js',
    '/usr/my/express/js/bin/www'
  ]
}
[nodemon] app crashed - waiting for file changes before starting...

As you can see above, I lost my ./config file, because I added it into .gitignore and when I cloned it on local machine, it lost.

Just retrieve the file back, and the problem solved!

Hi, i am struggling with the same problem. my log error is below. Please advise where to go from here. Thanks in advance:


/root/.pm2/logs/server-error.log last 15 lines:
0|server   | Require stack:
0|server   | - /var/www/api.diegotrainer.com/html/dt-express-backend/server.js
0|server   |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
0|server   |     at Module.Hook._require.Module.require (/usr/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
0|server   |     at require (internal/modules/cjs/helpers.js:72:18)
0|server   |     at Object.<anonymous> (/var/www/api.diegotrainer.com/html/dt-express-backend/server.js:120:32)
0|server   |     at Module._compile (internal/modules/cjs/loader.js:1137:30)
0|server   |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
0|server   |     at Module.load (internal/modules/cjs/loader.js:985:32)
0|server   |     at Function.Module._load (internal/modules/cjs/loader.js:878:14)
0|server   |     at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:32:23)
0|server   |     at Module._compile (internal/modules/cjs/loader.js:1137:30) {
0|server   |   code: 'MODULE_NOT_FOUND',
0|server   |   requireStack: [ '/var/www/api.diegotrainer.com/html/dt-express-backend/server.js' ]
0|server   | }

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.