Dan, Rick, and Angel are all correct, but it depends somewhat on the situation.

See https://npmjs.org/doc/folders.html for a thorough explanation of
how npm does this, and http://api.nodejs.org/modules.html for a
thorough explanation of how Node resolves require() calls to real
files.

Note that node caches modules based on the fully resolved filename, so
if two packages would get different files, they'll get different
instances of the module, as well.


On Mon, Jan 14, 2013 at 1:08 PM, Rick Waldron <[email protected]> wrote:
>
>
>
> On Mon, Jan 14, 2013 at 4:02 PM, Angel Java Lopez <[email protected]>
> wrote:
>>
>> Well, it could be that B uses C-0.0.1 (declared in its package.json), and
>> A uses C-0.0.2
>>
>> So
>>
>> A --> B --> C-0.0.1
>> A --> C-0.0.2
>>
>> node_modules/A/node_modules/B/node_modules/C <-- C-0.0.1 here
>> node_modules/A/node_modules/C <-- C-0.0.2 here
>>
>
> Thanks, I realized that I was dreadfully unclear about this in my response.
>
> Rick
>
>
>>
>>
>> On Mon, Jan 14, 2013 at 5:49 PM, Dan Milon <[email protected]> wrote:
>>>
>>> Dependencies (aka `require`s) are resolved synchronously.
>>>
>>> So the flow is:
>>> A --> B --> C
>>> A --> C
>>>
>>> Also modules are cached. [1] ie, they are not loaded twice. A and B
>>> "see" the same version of C.
>>>
>>> [1] http://nodejs.org/docs/latest/api/modules.html#modules_caching
>>>
>>> Hope this helps,
>>> danmilon.
>>>
>>> On 01/14/2013 09:45 PM, Thiago Souza wrote:
>>> > Hello all,
>>> >
>>> > I've got a basic dependency question. Consider the following
>>> > dependencies:
>>> >
>>> > (module A) --> (module B) (module A) --> (module C) (module B) -->
>>> > (module C)
>>> >
>>> > So, C is a shared dependency between A and B, but A also depends on
>>> > B. My question is, will A and B share the same C module instance?
>>> > If so, what code base will be used?
>>> >
>>> > Cheers, Thiago Souza
>>> >
>>> >
>>> >
>>> >
>>> > -- Job Board: http://jobs.nodejs.org/ Posting guidelines:
>>> > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>>> >
>>> >
>>> You received this message because you are subscribed to the Google
>>> > Groups "nodejs" group. To post to this group, send email to
>>> > [email protected] To unsubscribe from this group, send email
>>> > to [email protected] For more options, visit this
>>> > group at http://groups.google.com/group/nodejs?hl=en?hl=en
>>>
>>> --
>>> Job Board: http://jobs.nodejs.org/
>>> Posting guidelines:
>>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>>> You received this message because you are subscribed to the Google
>>> Groups "nodejs" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>>
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to