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
Asked
Active
Viewed 1.1k times
6

lulliezy
- 1,741
- 5
- 24
- 49
-
Mind sharing your `start` script? – rtn Apr 09 '18 at 07:53
2 Answers
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
-
-
@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
-
1your 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