Stop Using Nodemon for Development
In Node version 18.11+ you no longer need to use Nodemon for development!
What is Nodemon?
Nodemon is a command-line interface utility that helps us build Node applications by restarting the node application when it identifies file changes in the directory.
To normally run a Node.js app you would run:
But anytime there were changes to your app, you would need to run this script again. Nodemon, while running would detect changes and restart your Node app auto-magically.
Why don't you need Nodemon?
Node.js version 18.11+ introduced "watch" mode, which lets you get all of the benefits of Nodemon without needing to install a dependency in your project.
Simply use the
--watch flag when running a node command:
node --watch my-app.js
This will check for any changes in the file or its imports have changes and restart the server for you.
If you want to specify a folder to watch, you can be even more granular if needed (but I haven't found myself using it just yet), by using
--watch-path. By watching a path you can only restart your server if there have been updates in the folders selected:
node --watch-path=./src my-app.js
Or multiple paths:
node --watch-path=./src --watch-path=./scripts my-app.js
Nodemon has been awesome over the years, and I think we can all see what inspired the addition to Node.
So major kudos to Remy Sharp, who has been keeping us sane for all the years up to this moment!
Don't know how to change versions?
If you don't know how to change versions or want to be able to change them for multiple projects, check out my article on Volta the Node Version Manager.
🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉