Do you hate to restart Node Server every time you change the code. I hate to restart my Server every time i change the code and that really slows down my productivity and some time it irritates too.
i have found a quick solution to fix this thing. Guy named Remy Sharp developed node module called as “nodemon”. This module helps to automatically restart your Server once you made the changes in Source code. Pretty cool.
Installation is similar to other modules. But i prefer to install it globally in my System. Install nodemon by typing
You may need Sudo access in case of Linux or Mac based System.
How to use Nodemon:
To restart Node Server program we do this by using
but now you have to this using
Nodemon will deal with starting it on Specific port and handling code updates.
To show you a demo i have created on simple Node app which returns ‘Hello world’. Now i have started the file with nodemon and now if i make changes in my source code in editor and save the file it automatically restart the server for me. See below for screen shot.
Before making changes
After making changes:
As soon as i make change in source code and restart it, nodemon detects the changes and Restart the Server.
Restart manually without stopping Nodemon
If in case you want to restart nodemon without killing it and starting again. You can do this by typing rs on terminal and press enter. That’s it.
Manipulating Restart time:
Nodemon keeps on check whether the source changed or not and of course it does it by using some timer. By default the time is 1 second but if you want to change that too for obvious reason. You can do so by using following command.
You can specify time in milliseconds or seconds.
Nodemon is very useful in development stage. It really pains to stop the Server and restart it again, nodemon really gives us very peaceful solution. The source code is free and tested by many developers so don’t worry about its security or memory eating issue. I personally gonna start using it and Codeforgeek recommend this.