Synchronously execute a module function
npm install --save sync-module
Synchronous Module:
var Promise = require('promise');
// The module should always have a function to execute
// And it should return a promise
module.exports = function (a, b) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(a + b + 5);
}, 2000);
});
};
Calling code:
var syncModule = require('sync-module');
var result = syncModule(<path to file above>, [2, 7]);
// Result: 2+7+5=14
MIT