Reputation: 372
I read the npm documentation on npmjs.com for linking local packages and it says I need to do it in two steps:
npm link
npm link <package_name>
For example, if I want to use packageB
as a dependency in packageA
, I need to go to packageB
's directory, run npm link
, then do a npm link packageB
in packageA
's directory.
However, in practice, when I just to npm link
in packageB
's directory and then require('packageB')
inside packageA
, it works, and any changes in packageB
are instantly reflected in packageA
.
Can anyone tell me how this is happening?
Upvotes: 0
Views: 38
Reputation: 301
In fact when you do 'npm link', it create a link to you package globally on your system (you know it's something like when you do a "npm install -g xxx").
And when you require a package via Node it checks at many directory (the current node_modules, the parent ... & the global directory )
Upvotes: 1