Nodemon has been our trusty friend, helping Node.js developers by automatically restarting our servers whenever we made changes to our code.
So if you donβt know what nodemon is, according to their official website:
βNodemon is a utility depended on about 3 million projects, that will monitor for any changes in your source and automatically restart your server. Perfect for development.β (nodemon.io, 2023).
npm install -g nodemon #install it globally
npm install -D nodemon #install it locally (dev dependency)
nodemon server.js localhost 8080 #then to run your local dev server
But now, with the release of Node.js 18, we don't need Nodemon anymore. Node.js 18 comes with a cool new feature called "--watch" that does the same thing. In this article, we'll explore how to use this built-in feature and enjoy an easier coding experience.
The Magic of "--watch"
With Node.js 18, we now have a built-in solution for auto-reloading, which means we can say goodbye to Nodemon. The magic is in the "--watch" feature. It allows Node.js to keep an eye on our code and automatically restart the server whenever we make changes.
- For a Single Entry Point File:
node --watch server.js
- For Multiple Watch Paths:
node --watch-path=./src --watch-path=./tests index.js
- Disabling Console Output Clearing:
node --watch --watch-preserve-output server.js
Goodbye, Nodemon! π It's been a wild ride, but we're ready to embrace change and explore new horizons. We'll forever cherish the auto-reloading memories, but it's time to move forward without you. #NewChapter #NoMoreNodemon
Top comments (2)
To be honestly, gulp's file watch thingy works much better than nodemon.
I used that code snipper through my career to quickly set it up
Then just run
npx gulp start_dev
to start it upAbsolutely, I appreciate your input! π§‘