Skip to content

Instantly share code, notes, and snippets.

@joepie91 joepie91/some-module.js

Last active Apr 20, 2017
What would you like to do?
Configurable module using closures in Node.js / CommonJS (ie. parametric modules)
module.exports = function(config) {
return function actualFunctionality(someArgument){
return doSomethingWith(config).and(someArgument);
module.exports = function(config) {
return {
functionalityOne: function(someArgument) {
return doSomethingWith(config).and(someArgument);
functionalityTwo: function(someArgument) {
return doSomethingElseWith(config).and(someArgument);
var config = loadConfiguration("config.js");
var someModule = require("./some-module")(config);
var someObjectModule = require("./some-object-module")(config);

This comment has been minimized.

Copy link

sparr commented Mar 11, 2017

Can you provide an example of what might be in config.js?

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.