Skip to content

Instantly share code, notes, and snippets.

@dkolb
Last active December 24, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkolb/6731361 to your computer and use it in GitHub Desktop.
Save dkolb/6731361 to your computer and use it in GitHub Desktop.
Node.js Module Globals Example
var b = require(__dirname + "/b"),
c = require(__dirname + "/c");
b.doIt();
console.log(c.get()); //Outputs 'b.doIt is updating stuff!'
var c = require(__dirname + '/c');
module.exports.doIt = function() {
c.update("b.doIt is updating stuff!");
}
var x;
module.exports.update = function(y) {
x = y;
}
module.exports.get = function() {
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment