Nodejs
Several Node module / library modules can be downloaded, depending on where they are loaded. the module loader is described in detail in the Node.js documentation .
require()the call caches the modules based on the allowed file path.
require('b')from the module will aallow.../a/node_modules/b
require('b')from the module will callow.../a/node_modules/c/node_modules/b
Therefore, separate modules will be loaded for the same call. This can be demonstrated with a small example.
Module B - node_modules/b/index.js
module.exports = {
VERSION = 'b-0.5.0'
}
Module C - node_modules/c/index.js
module.exports = {
VERSION: 'c-1.0.0',
BVERSION: require('b').VERSION,
}
Module C Copy B - node_modules/c/node_modules/b/index.js
module.exports = {
VERSION: 'b-9.8.7',
}
.
console.log('b', require('b').VERSION)
console.log('c', require('c').VERSION)
console.log('cb', require('c').BVERSION)
→node index.js
b b-0.5.0
c c-1.0.0
cb b-9.8.7
, require('b').VERSION .
Traversal
, Node.js require('b') ./node_modules/b, , b node_modules.
, a/node_modules/c/node_modules/b.
c require('b'), ...a/node_modules/c/node_modules/b, node_modules/ b. ...a/node_modules/b
→node index.js
b b-0.5.0
c c-1.0.0
cb b-0.5.0
npm. , CommonJS-, Browserify Webpack. CommonJS/ Node.js, npm.
, .