Last Updated: February 25, 2016
·
1.173K
· 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

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside