DEV Community

Cover image for Farewell, Nodemon! πŸ’”
Bilal Asghar
Bilal Asghar

Posted on

Farewell, Nodemon! πŸ’”

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


Enter fullscreen mode Exit fullscreen mode



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.

Image description

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


Enter fullscreen mode Exit fullscreen mode
  • For Multiple Watch Paths:


node --watch-path=./src --watch-path=./tests index.js


Enter fullscreen mode Exit fullscreen mode
  • Disabling Console Output Clearing:


node --watch --watch-preserve-output server.js


Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
alice58 profile image
Alice 🌈 • Edited

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

// gulpfile.js
const gulp = require('gulp');
const spawn = require('child_process').spawn;

gulp.task('start_dev', (cb) => {
    console.log('Running in dev mode');

    const spawn_node = () => {
        return spawn('node', [ '--inspect=0.0.0.0:9229', 'src/index.js' ], { stdio: 'inherit' });
    }

    let node = spawn_node();

    function files(cb) {
        console.log('Restarting node');
        node.kill('SIGTERM');
        node = spawn_node();
        cb();
    }

    gulp.watch('**', { events: 'all' }, files);

    cb();
})
Enter fullscreen mode Exit fullscreen mode

Then just run npx gulp start_dev to start it up

Collapse
 
malikbilal111 profile image
Bilal Asghar

Absolutely, I appreciate your input! 🧑