NodeJS Auto-reload server
Published on December 23, 2020
This document was migrated from DigiDocs
Problem: Manually reloading the NodeJS server by hitting Ctrl + C and entering npm start repeatedly in development is exhausting.
Solution: Automatically reload the server each time there is a change!
Nodemon
Cite
Nodemon is a utility that will monitor for any changes in your source and automatically restart your server.
How-to-use
npm i -g nodemon
- Install nodemon:npm i -g nodemon.
- Replace nodewithnodemonin your command. For example, changenode index.jstonodemon index.js. That's it.
Add to npm scripts
You can also add it to npm scripts to make life even easier.
{
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  }
}
After doing so, you can enter npm run dev subsequently, which will resolve to nodemon index.js.