I am trying to start pm2 if it is not running, or kill it and start if it is, how can I achieve this behavior in the WINDOWS command line interface?
There are plenty of solutions using grep in linux but nothing for windows, any idea on how to get this behaviour?
The documentation says that pm2 start -f app.js
will kill and start the app but it actually just creates another instance.
Use this:
pm2 delete main.js 2> /dev/null && pm2 start main.js
This part: 2> /dev/null
- will simply redirect the stderr to the /dev/null
, meaning to nowhere.
You can do something like this
pm2 delete your_app_name || : && pm2 start index.js -i 1 --name 'your_app_name'
The :
is a null operator that returns 0 success exit code. So whatever happens, pm2 start
command will execute (even if pm2 delete
fails, for the case where the app does not exist yet).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With