Some very brilliant programmers found that this constantly stopping and restarting the server during the development phase, was very annoying. So they developed an npm package called nodemon, which will automatically restart your server for you when it detects any file changes in the directory.
nodemon is a npm package, so it needs to be installed. It is also recommended that you install it with a "global" scale, using the -g option:
- npm i -g nodemon
Once nodemon is installed, when you run your file from the terminal, you just replace node fileName.js with nodemon fileName.js, and you're all set. Once the server is running under nodemon, every time you make changes to your file, nodemon will automatically stop and restart the server for you.