Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This node module will consume another module and promisify all of its functions.
const {promisify} = require('util');
const promisifyModuleFunctions = (inModule) => Object
.entries(inModule)
.reduce((outModule, [key, property]) => {
outModule[key] = (typeof property === 'function')
? promisify(property)
: property;
return outModule;
}, {});
module.exports = {
promisifyModuleFunctions,
requireWithPromises: (moduleName) => promisifyModuleFunctions(require(moduleName))
};
@manuelbieh

This comment has been minimized.

Copy link

commented Dec 12, 2018

module.exports = (inModule) => Object.entries(inModule).reduce((outModule, [name, method]) => {
	outModule[name] = (typeof method === 'function')
		? promisify(method)
		: method;

	return outModule;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.