Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an app that I'm working on that is three separate modules. All three modules will be packaged separately and stored in a private NPM repository. So each module will have it's own index.js, package.json, etc.

Module A depends on Module B and Module C. Module B depends on Module C.

Dependency Chart

Because Module A and Module B both have a dependency on Module C, will they share the dependency?

For instance, let's say that Module C has a singleton.js file that returns a singleton.

singleton.js

class MyClass {

}

const instance = new MyClass();

module.exports = instance;

And then the index.js for Module C exports that as well.

const myClassSingleton = require('./lib/singleton.js')

module.exports = myClassSingleton;

If both Module A and Module B require Module C

const moduleC = require('module-c');

Are they both sharing that same instance of that Singleton?

question from:https://stackoverflow.com/questions/66054549/do-the-npm-modules-in-my-node-app-share-dependencies

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...