6

In my package.json file I have two scripts, start and production, start script is for local development while production script is for deployment. Using npm i would just do npm run production but how do I do this with pm2

lulliezy
  • 1,741
  • 5
  • 24
  • 49

2 Answers2

7

I got it, the command is pm2 start npm --name=app-name -- run production

lulliezy
  • 1,741
  • 5
  • 24
  • 49
  • Hello, I tried your solution but I'm always getting the same error : SyntaxError: Unexpected token : 0|backend- | at createScript (vm.js:80:10) 0|backend- | at Object.runInThisContext (vm.js:139:10) – Benjamin D. Nov 05 '18 at 15:02
  • 1
    @BenjaminD. try `pm2 start npm --name=app -- start` – lulliezy Nov 06 '18 at 05:16
  • It's not working for me. I get an error "Script not found" – vijayst Mar 13 '20 at 18:33
  • @vijayst can you please ask the pm2 forum, because this has always worked for me and frankly i have no other tricks in my sleeves – lulliezy Mar 14 '20 at 16:18
0

Install pm2 globally using npm i -g pm2 and then use pm2' command as follow:

pm2 start npm -- production

Farhan Tahir
  • 2,096
  • 1
  • 14
  • 27
  • 1
    your command only works for start, in case of production it works with `run production` instead of `production` only – lulliezy Apr 09 '18 at 12:58
  • today i ran my app with : **npm run nameScript** ,this shot two service in two ports... **How can do it with pm2?** – puentesdiaz May 27 '21 at 19:34