26

I'm running my app using sudo npm run dev how should I use pm2 in order to run sudo npm run dev this command.

Asmita Bhiware
  • 383
  • 1
  • 3
  • 9

5 Answers5

66

The following works for me.

pm2 start "npm run dev" --name myAppName

Your app name will be myAppName

You can see the logs

pm2 logs "myAppName"
zenny
  • 866
  • 7
  • 11
  • You can also specify the app name with --name argument, like this: `pm2 start "npm run dev" --name myAppName` Then you can see logs by `pm2 logs myAppName` Also, please don't use `sudo` until it's really necessary (in most cases, pm2 can work fine without sudo). – Maxím G. Jan 26 '19 at 22:20
3

Try this: sudo pm2 start npm -- dev

bumbleshoot
  • 1,082
  • 2
  • 17
  • 32
2

The answer given by @zenny is correct, I want to add that

pm2 start "npm run dev" --name myAppName

try running the above command logged in as a root user instead of a non-root user. I had the same error in AWS ubuntu, it worked me.

0

In your package.json file, you will define the scripts for npm to run.

So, you can change your file to look something like this:

 "scripts": {
    "dev": "pm2 start app.js"
  },
Shimon Brandsdorfer
  • 1,673
  • 9
  • 23
0

Also: pm2 start npm -- run dev

(I didn't need to use the app name bits)

Darren Shewry
  • 10,179
  • 4
  • 50
  • 46