Do the NPM modules in my node app share dependencies?

Viewed 288

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?

0 Answers
Related