Just a tiny gist to illustrate node shares required dependencies between different files that require the same module. Modifying underscore in the parent file modified it for the child files as well.
Created
July 2, 2013 05:10
-
-
Save dcneiner/5906901 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require( "underscore" ); | |
module.exports = { | |
_: _, | |
run: function () { | |
console.log( _.amazing ); | |
console.log( _.after ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require( "underscore" ); | |
module.exports = { | |
_: _, | |
run: function () { | |
console.log( _.amazing ); | |
console.log( _.after ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "http-server", | |
"version": "0.0.1", | |
"author": "Doug Neiner <[email protected]>", | |
"main": "./parent.js", | |
"dependencies" : { | |
"underscore" : "*" | |
}, | |
"license": "MIT", | |
"engines": { | |
"node": ">=0.10" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require( "underscore" ); | |
_.amazing = "Awesome"; | |
var m1 = require( "./module1.js" ); | |
var m2 = require( "./module2.js" ); | |
_.after = "This too"; | |
// Expects: "Awesome" | |
// Expects: "This too" | |
m1.run(); | |
// Expects: "Awesome" | |
// Expects: "This too" | |
m2.run(); | |
// Expects: true | |
console.log( m1._ === _ ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment