Using PM2 to run other npm scripts
Asked Answered
P

2

7

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

Pyrrhuloxia answered 9/4, 2018 at 6:49 Comment(1)
Mind sharing your start script?Clap
P
8

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

Pyrrhuloxia answered 9/4, 2018 at 12:59 Comment(4)
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)Metaphor
@BenjaminD. try pm2 start npm --name=app -- startPyrrhuloxia
It's not working for me. I get an error "Script not found"Unmade
@Unmade can you please ask the pm2 forum, because this has always worked for me and frankly i have no other tricks in my sleevesPyrrhuloxia
P
0

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

pm2 start npm -- production

Prent answered 9/4, 2018 at 6:54 Comment(2)
your command only works for start, in case of production it works with run production instead of production onlyPyrrhuloxia
today i ran my app with : npm run nameScript ,this shot two service in two ports... How can do it with pm2?Discombobulate

© 2022 - 2024 — McMap. All rights reserved.