The message “[nodemon] clean exit – waiting for changes before restart” is a log message generated by the nodemon tool, which is a utility for automatically restarting the Node.js application whenever changes are detected in the project files.
This particular message indicates that the Node.js application has exited gracefully and is now waiting for any changes in the project files before it restarts. During this waiting period, if any file changes are detected, nodemon will automatically restart the application to reflect those changes.
Here is an example to better understand this scenario:
// Let's say you have a Node.js application called app.js
// Inside app.js, you have a simple HTTP server logic
const http = require('http');
const server = http.createServer((req, res) => {
res.write('Hello World!');
res.end();
});
server.listen(3000, () => {
console.log('Server is running on port 3000');
});
Now, if you start the application using nodemon:
$ nodemon app.js
It will start the application and you will see the log message:
[nodemon] starting `node app.js`
Server is running on port 3000
Now, let’s say you make changes to the app.js file, for example, changing the response message to “Hello from Nodemon!”.
const http = require('http');
const server = http.createServer((req, res) => {
res.write('Hello from Nodemon!');
res.end();
});
server.listen(3000, () => {
console.log('Server is running on port 3000');
});
After saving the changes, nodemon detects the file change and restarts the application:
[nodemon] clean exit - waiting for changes before restart
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
Server is running on port 3000
As you can see, the log message “[nodemon] clean exit – waiting for changes before restart” indicates that the previous instance of the application has exited gracefully. Nodemon then detects the file change and starts the application again, resulting in the message “Server is running on port 3000” being printed.
This kind of automatic restart capability provided by nodemon is helpful during development as it saves the time required to manually stop and start the application after every file change.