nodemon and Restarting
nodemon is a tool that restarts a Node program when its files change. A restart means the program stops and starts again with the new code.
Install nodemon
This command installs nodemon for building.
npm install --save-dev nodemonRun with nodemon
This command runs the program through nodemon.
npx nodemon app.jsExample
console.log("Hello from nodemon");Key points
- nodemon is a tool that restarts a Node program when its files change.
- Install it with npm install --save-dev nodemon.
- The --save-dev part marks nodemon as a tool for building.
- Run it with npx nodemon app.js.
- npx is a runner that finds a local tool and runs it.
- nodemon watches the files and restarts on each save.
In this example, app.js prints one line. The npx nodemon line starts nodemon on app.js. nodemon prints its version, 3.1.14, and the files it watches. It starts the program, and the program prints Hello from nodemon. Then nodemon waits for a file change.
Note
nodemon suits learning, not a public server.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does nodemon do when a file changes?