Spawn child_process on directory

How to spawn this command (/usr/bin/which flac) on node.js:

var spawn = require('child_process').spawn;
var cmd = spawn('/usr/bin/which flac', parameters);

I've tried that code but its not working, assuming that parameters variables are set.

In your case, flac needs to be passed as a parameter. Try this:

var spawn = require('child_process').spawn;
var cmd = spawn('/usr/bin/which', ['flac'], {detached:true, stdio: 'inherit'})
.on('exit',function(code){
  //check exit code
});

For example, running the same code with node instead of flac gives:

/usr/bin/node