简体   繁体   English

node.js包的正确位置是什么

[英]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. 现在,当您意识到我正在Windows上运行节点时,我可以听到一声叹息,但它工作正常。 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. 无论如何,当我运行npm ls它仅列出C:\\nodejs\\node_modules中的软件包,这使我认为这是正确的位置。 But then noticed that the npm itself is in C:\\nodejs\\lib\\node_modules which makes me think that's the correct location. 但是随后发现npm本身位于C:\\nodejs\\lib\\node_modules ,这使我认为这是正确的位置。 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. 我已经将模块从C:\\nodejs\\node_modules移到了C:\\nodejs\\lib\\node_modules ,它们仍然可以正常工作。

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 我碰巧将代码存储在H:\\dos\\pd所以我的node_modules放入H:\\dos\\pd\\node_modules

That's just my pd modules of course. 那当然是我的pd模块。 If I'm working on some other code it goes in Drive:\\some\\sensible\\location\\node_modules 如果我正在处理其他一些代码,它将进入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. 通常,模块在系统范围内(通常为/lib/node_modules/ ),但是每个项目都可以使用所需的确切版本维护其modules文件夹。 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. 如果到处都有node_modules文件夹,它可能会变得混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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