`npm link` works even when I do not `npm link ` in the desired directory

Home / Uncategorized / `npm link` works even when I do not `npm link ` in the desired directory

Question:
I read the npm documentation on npmjs.com for linking local packages and it says I need to do it in two steps:Navigate to the local package dir and run npm link
Navigate to the package in which I intened to use this package and run npm link

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?


Answer:
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 )
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *