aditya_medhe
aditya_medhe

Reputation: 372

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

I read the npm documentation on npmjs.com for linking local packages and it says I need to do it in two steps:

  1. Navigate to the local package dir and run npm link
  2. Navigate to the package in which I intened to use this package and run 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

Answers (1)

nodeover
nodeover

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

Related Questions