Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run node server with PM2

Tags:

node.js

npm

pm2

How could I run node server.js -p by pm2?

Scripts of my package.json is like below,

 "scripts": {
    "dev": "node server.js",
    "start": "node server.js -p"
  },

When I execute npm start everything work truly. But I want to run this command with pm2.

To do it when I run pm2 start npm -- start, the process will add to the list of the pm2 but my app not run!

like image 622
Behnam Azimi Avatar asked Jun 06 '26 02:06

Behnam Azimi


1 Answers

the correct command is

pm2 start server.js

or if you want to pass -p to your app and a name

pm2 start server.js --name "my-server" -- -p
like image 85
Simone Sanfratello Avatar answered Jun 08 '26 22:06

Simone Sanfratello