Last Updated: February 25, 2016
·
810
· johannesboyne

watch + make with node.js

watch is great but here is a solution for the nodejs fan-boys (like I am):

#!/usr/bin/env node

var fs = require('fs');
fs.watch(process.argv[2], function (fsWatch) {

    var spawn = require('child_process').spawn,
        pro  = spawn(process.argv[3], [process.argv[4]]);

    pro.stdout.on('data', function (data) {
        console.log('(log): ' + data);
    });

    pro.stderr.on('data', function (data) {
        console.log('(error): ' + data);
    });
});

use it like this:

$ ./watch.js text.txt make test