Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running concurrent commands with npm on windows?

Tags:

node.js

npm

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.

like image 692
Joren Avatar asked Sep 11 '14 02:09

Joren


2 Answers

I developed concurrently just for this purpose. For example cat a & cat b can be achieved with concurrently 'cat a' 'cat b'. Concurrently also provides a few output formatting options for convenience.

Install it as dev dependency npm install --save-dev concurrently and then it's ready to be used in package.json "scripts".

like image 158
Kimmo Avatar answered Oct 23 '22 15:10

Kimmo


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');
like image 32
mscdex Avatar answered Oct 23 '22 16:10

mscdex