Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

javascript - Do the NPM modules in my node app share dependencies?

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

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...