You have to pass a callback to your test()
function:
var chproc = require('child_process');
Test.prototype.write = function(m, cb) {
chproc.execFile(
'./mainCmd',
['-o', '\\!' + m + '.'],
function(error, stdout, stderr) {
if (error) return cb(error);
cb(null, stdout);
}
);
};
// usage ...
var t = new Test();
t.write('foo', function(err, result) {
if (err) throw err;
// use `result`
});