Sam Thorogood

Sents File Watcher for Node

In December 2020, I wrote a pure-JS file watcher called sents. It has zero dependencies and doesn't use any native code (no weird bindings) yet is still quite speedy.

There's also the command-line version, which just has three dependencies in total. You can use it to watch files to rebuild in your projects.

# add to your project
npm install --save-dev sents-cli

# for info on command-line args
sents --help

# watch your JS files and rebuild on changes
sents "**/*.js" -c "npm run build"

You can specify -c to run a command, or leave it off just to see a log of changed files, like this:

$ sents "*.json"
Watching "*.json" ...

This is a kind of announcement post, even though the code is six months old (I just cleaned up a few issues today). Why should you use this?

Zero/Low Dependencies

Whenever possible, I want my Node dependencies to themselves have zero dependencies—or as few as possible, with an explanation to why they're needed. Every dependency you add (even this library) increases the surface area of your project. (Some projects even mask this by bundling their dependencies further, but that's for a different post.)

No Native Code

Node's native bindings—I'm sure someone understands them, but they present the most amazingly opaque errors for users. I even wrote a touch about this when I spoke about Atomics.

I also dispute that tools like file watchers actually need native bindings. Sure, Node's built-in methods aren't great, but all it takes is a tiny bit of massaging of its results to get something performant.


Here are some concessions I've made in sents to get performance up:

On Linux, Node can't watch a folder recursively, so we have to recurse and watch every subfolder (unlike on macOS and Windows, where Node's built-in calls support this). But there's not a native method to do this anyway, so every watcher is doing this, and it's not really a concession 🤷

That's it

Click the links. Use it in your project!