TayDex
TayDex

Reputation: 48

Express JS code doesnt work with pm2, but when started manually ("node ."/"node index.js")

I got a Discord JS project running which works fine, now I wanted to also run a simple express script to receive a post request. When I do "node ." the code works and successfully logs the requests, if I do "pm2 start index.js --name xyz" the code also starts, logs its boot up message, doesn't shut down, but also doesn't react to any requests. There is simply no response at the set port by express.

Running on an Ubuntu VPS.

Upvotes: 0

Views: 169

Answers (3)

Jaime Reynoso
Jaime Reynoso

Reputation: 146

For me it seems to be the node version run pm2 and then do pm2 start --node-version 18

Upvotes: 0

José Henrique
José Henrique

Reputation: 336

You can read about arguments on the official docs

It's likely you have a runtime error. Please read your own logger files and ~/.pm2/logs/*.log and see if you can find anything. Had it been a syntax error, it would have shut down immediately. Yet, always pm2 statusafter start to double check it.

Upvotes: 0

TayDex
TayDex

Reputation: 48

Works if I do "pm2 start index.js --name xyz -- --port XXXX" I don't know why and would like to know how these extra arguments work if anyone could explain.

Upvotes: 0

Related Questions