开发者

What is the correct location for node.js packages

开发者 https://www.devze.com 2023-04-12 06:51 出处:网络
I\'ve noticed that packages are installing themselves into t开发者_如何学编程wo different places and I wondered which one is correct, or maybe it doesn\'t matter. The two locations are;

I've noticed that packages are installing themselves into t开发者_如何学编程wo different places and I wondered which one is correct, or maybe it doesn't matter. The two locations are;

C:\nodejs\lib\node_modules
C:\nodejs\node_modules

Now I can hear the sighs as you realise I'm running node on windows but it works fine. Kind of:)

Anyway, when I run npm ls it only lists packages in C:\nodejs\node_modules which makes me think that's the correct location. But then noticed that the npm itself is in C:\nodejs\lib\node_modules which makes me think that's the correct location. Is there a correct location? They all seem to work fine. I've moved modules from C:\nodejs\node_modules to C:\nodejs\lib\node_modules and they still work OK.

Your answers will be greatly appreciated.


Packages go here

Drive:\path\to\your\code\node_modules

I happen to Store my code in H:\dos\pd so my node_modules goes in H:\dos\pd\node_modules

That's just my pd modules of course. If I'm working on some other code it goes in Drive:\some\sensible\location\node_modules


There are different locations in which modules are searched for.

The documentation about modules describes in detail how node searches for modules. Normally there's a system-wide location for modules (often /lib/node_modules/), but every project can maintain its modules folder with the exact versions it needs. Those override the global modules.

There's not really a right and wrong. It just can get messy if there are node_modules folders everywhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号