Can pm2 run an 'npm start' script
To use npm run
pm2 start npm --name "{app_name}" -- run {script_name}
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.
PM2 now supports npm start:
pm2 start npm -- start
To assign a name to the PM2 process, use the --name
option:
pm2 start npm --name "app name" -- start