Watch Files in Node Project with Native Features
Since Node.js v18.11.0 , you can automatically restart your scripts when files change, without installing any extra packages. This addition finally brings Node's watch mode closer to what external tools like Nodemon have offered for years. But should you switch to it right away? To find out, I decided to rely solely on Node's built-in watch mode to explore how far it can go. In this post, I won't spend much time on the basic --watch flag, since it only monitors changes to the script being executed. What really interests me is the --watch-path parameter, which lets you watch entire directories or specific files in the file system. I will also introduce the fs.watch method from Node's core fs module, which provides more flexibility and can be used to build scalable custom watch solutions. For this post, I set up a small demo project that builds a progress bar web component . I use Rollup to bundle the modules into a single pr...