简体   繁体   中英

What is the correct location for node.js packages

I've noticed that packages are installing themselves into two 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM