Last active
August 29, 2015 14:03
-
-
Save bendrucker/82beed49ab13d037f107 to your computer and use it in GitHub Desktop.
Node module caching
This file contains 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 count = 0; | |
count++; | |
module.exports = count; |
This file contains 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
require('./counter') // => 1 |
This file contains 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
require('./counter') // => 1 |
This file contains 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
// count reference does not exist yet | |
// resolve and initialize the counter module | |
// it creates a counter reference as 0, increments it, and exports it | |
require('./counter'); | |
// retrieve the cached counter module | |
// count reference is unchanged because counter is not re-evaluated | |
require('./dep1'); | |
require('./dep2'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment