Open Menu

    Streamline your development with Node.js v18's "--watch" and "--watch-path" flags

    Flavio Del Grosso

    Flavio Del GrossoFeb 2, 2023

    2 min read405 words

    Have you ever found yourself wishing for a simpler way to automatically reload your Node.js server whenever you make changes to your code? If so, you're in luck! With the release of Node.js version 18.11.0, there's a new feature that can replace the popular utility Nodemon.

    --watch

    That's right, the --watch flag has arrived on the scene. This flag allows you to specify a file that you want Node.js to keep an eye on. And, if any changes are made to that file, Node.js will automatically restart the process for you.

    Not only is the --watch flag super simple to use, it's also built right into Node.js, so you don't need to worry about installing any additional packages. To use it, just add the flag to the command you use to run your Node.js script.

    For example, instead of running the following command:

    bash

    nodemon index.js

    you can now use:

    bash

    node --watch index.js

    --watch-path

    It's also worth mentioning that the --watch flag has a sibling, the --watch-path flag. This allows you to specify a specific directory to watch, rather than just files. How cool is that?!

    Say goodbye to Nodemon and hello to a faster and smoother development process.


    Share on