How to properly restart nodemon server
Solution 1
The purpose of nodemon
is to listen changes of the file and restart the server. If you want manually to restart the server then you no need to use nodemon, you can use just node
command.
The below code would serve the purpose.
{
"scripts": {
"start": "node ./src/app.js",
"restart": "kill -9 $(ps aux | grep '\snode\s' | awk '{print $2}') && node ./src/app.js "
},
}
Solution 2
As stated in the documentation, you can restart manually by typeing rs
in the console where nodemon
is running.
There is no external command to trigger a restart from a different process.
One workaround would be to trigger a restart by simulating a change of a file.
A simple touch
on a watched file is enough. So you could write a npm script that touches one of the watched files.
"restart": "touch app.js"
KasparTr
Updated on June 20, 2022Comments
-
KasparTr almost 2 years
When I run a nodejs server with the following command:
"start": "nodemon --max-old-space=8192 ./src/app.js --exec babel-node"
and I change anything in the code, nodemon automatically reloads the code and restarts the server with the following message.
[nodemon] restarting due to changes... [nodemon] starting `babel-node --max-old-space=8192 ./src/app.js`
How do I restart the server manually the same way?
Or in other words: What do I write in the package.json scripts "restart" command to simulate the same behaviour that is done by nodemon automatically?
Thanks