Watch a file or directory and execute a command when it changes.


Proximity is a tiny program that executes a command when a file or directory has changed. I use it to run a build script when I modify the source for a project I'm working on.

Proximity requires node.js and npm. Once you have these dependencies, simply:

npm install proximity -g

The first argument after proximity is the command to run. All following arguments are paths to watch.

For example, the following command will run ./ && ps aux | grep node whenever server.js or static/ are changed.

proximity "./ && ps aux | grep node" server.js static/

Proximity should only be used to run commands that will exit at some point because a separate child process is spawned on each change detected.

  • Catch errors:
    • File/directory doesn't exist.
  • Throttle commands so they don't run multiple times when incorrectly reports multiple changes.