Is there a way for pm2 to run an npm start script or do you just have to run pm2 start app.js
So in development
npm start
Then in production with pm2 you would run something like
pm2 start 'npm start'
There is an equivalent way to do this in forever
forever start -c "npm start" ./
PM2 now supports npm start:
pm2 start npm -- start
Those who are using a configuration script like a .json file to run the pm2 process can use npm start or any other script like this -
my-app-pm2.json
{
"apps": [
{
"name": "my-app",
"script": "npm",
"args" : "start"
}
]
}
Then simply -
pm2 start my-app-pm2.json
Edit - To handle the use case when you have this configuration script in a parent directory and want to launch an app in the sub-directory then use the cwd attribute.
Assuming our app is in the sub-directory nested-app relative to this configuration file then -
{
"apps": [
{
"name": "my-nested-app",
"cwd": "./nested-app",
"script": "npm",
"args": "start"
}
]
}
More detail here.
Yes. Use pm2 start npm --no-automation --name {app name} -- run {script name}. It works. The --no-automation flag is there because without it PM2 will not restart your app when it crashes.
I wrote shell script below (named start.sh).
Because my package.json has prestart option.
So I want to run npm start.
#!/bin/bash
cd /path/to/project
npm start
Then, start start.sh by pm2.
pm2 start start.sh --name appNameYouLike
To use npm run
pm2 start npm --name "{app_name}" -- run {script_name}
See to enable clustering:
pm2 start npm --name "AppName" -i 0 -- run start
What do you think?
Yes we can, now pm2 support npm start, --name to species app name.
pm2 start npm --name "app" -- start
Unfortunately no luck with running script start:prod.
"scripts": {
"start:prod": "node index.js"
},
Command pm2 start npm -- run start:prod crashes
Unfortunately, it seems that pm2 doesn't support the exact functionality you requested https://github.com/Unitech/PM2/issues/1317.
The alternative proposed is to use a ecosystem.json file Getting started with deployment which could include setups for production and dev environments. However, this is still using npm start to bootstrap your app.
Now, You can use after:
pm2 start npm -- start
Follow by https://github.com/Unitech/pm2/issues/1317#issuecomment-220955319
pm2 start ./bin/www
can running
if you wanna multiple server deploy you can do that. instead of pm2 start npm -- start
Don't forget the space before start
pm2 start npm --[space]start
so the correct command is:
pm2 start npm -- start
来源:https://stackoverflow.com/questions/31579509/can-pm2-run-an-npm-start-script