Joren Joren - 1 year ago 138
Node.js Question

Running concurrent commands with npm on windows?

I'm trying to set up a script in package.json which runs all my various watches for Coffeescript/Sass/etc.

This is the script I'm using on my server, which works fine.

"dev": "coffee --watch --compile js/ & coffee --watch --compile controllers/ & supervisor -e html,js js/index.js",

When I try that same script locally however, it only seems to run the first command. Windows doesn't seem like it knows what to do with the &. Every command there works fine run individually, but they won't all execute together.

Answer Source

For Windows, the built-in equivalent to & is instead prefixing the command with start /B. So you may just have "dev" set to a small node script that uses the built-in child_process to do something like:

var exec = require('child_process').exec;
var prefix = (process.platform === 'win32' ? 'start /B ' : '');

exec(prefix + 'coffee --watch --compile js/');
exec(prefix + 'coffee --watch --compile controllers/');
exec(prefix + 'supervisor -e html,js js/index.js');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download