问题描述
我对npm
的了解是:
它是Node.js
应用程序的程序包管理器.这意味着,当您需要其他人的节点应用程序的库/程序包时,可以方便地使用npm
获取这些依赖项.
It is a package manager for Node.js
applications. What this means is that when you need someone else's library/package for your node application you can conveniently use npm
to get those dependencies.
但是我最近遇到了这个命令:
But I recently came across this command:
npm install -g cca
.
然后我在终端中输入cca
,现在它启动了一些程序.
Then I enter cca
in my terminal and now it starts some program.
现在我的问题是npm
如何安装可以通过终端访问的软件包?我的意思是npm
安装的所有软件包都可以通过节点应用程序代码(在JavaScript中)进行访问.这使我感到困惑.
Now my question is how can npm
install packages that can be accessed via the terminal?I mean all packages installed by npm
should be accessible by node application code (in JavaScript). This confuses me.
推荐答案
听起来像您的主要问题不是如何,而是为什么?
Sounds like your primary question is not how, but why?
这里的区别是节点 package 和节点 module 之间.
The distinction here is between a node package vs a node module.
只有* module *可以被其他节点应用程序require()
所使用,并且npm
上的所有 packages 不一定都是 modules .有很多有用的节点包仅与节点间接相关.例如gulp
或grunt
或cordova
或cca
等
Only *module*s are meant to be require()
ed by other node applications, and not all packages on npm
need be modules. There are very many useful node packages that are only indirectly related to node. E.g., gulp
or grunt
or cordova
or cca
, etc.
这些答案直接来自(重新措词) npm常见问题解答
These answers come (reworded) directly from the npm faq
对于cca
具体来说,我们希望将来有一个节点 module ,因此为什么要使用npm"这个问题只是前瞻性考虑.另外,cca
是cordova
的下游发行版(就像phonegap
一样),该发行版始终托管在npm
上,我们希望继续沿袭这一传统.
For cca
specifically, we hope to have a node module in the future, so the question of "why npm" is just forward thinking. Additionally, cca
is a downstream distribution of cordova
(just like phonegap
) which was always hosted on npm
, and we wanted to continue that heritage.
这篇关于如何使用npm安装甚至在Node应用程序中不使用的全局软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!