Skip to content

Instantly share code, notes, and snippets.

@Paratron
Last active December 12, 2018 15:11
Show Gist options
  • Save Paratron/658c80499d67625ed9c3cb80a5d3bcbd to your computer and use it in GitHub Desktop.
Save Paratron/658c80499d67625ed9c3cb80a5d3bcbd to your computer and use it in GitHub Desktop.
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
Copy link

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