Licence
MIT
Version
2.2.0
Deps
8
Size
143 kB
Vulns
0
Weekly
0
function-exec-sync
Run an exported function in a Node.js process and return its value.
npm install function-exec-sync
Create worker.cjs:
module.exports = function (name, count) {
return Array(count + 1).join(name);
};
Call it from another CommonJS file:
var path = require('path');
var call = require('function-exec-sync');
var result = call(path.join(__dirname, 'worker.cjs'), 'ha', 2);
console.log(result); // "haha"
Pass execPath in an options object to select a Node executable:
var result = call({ execPath: '/path/to/node' }, path.join(__dirname, 'worker.cjs'), 'ha', 2);
The target module, arguments, and returned value cross a process boundary, so keep them serializable by this package. Circular values are not supported.