当前目录中的npm install模块 [英] npm install module in current directory
问题描述
当我跑步时:
npm install my-app
该应用已安装到node_modules/my-app/...
The app is installed into node_modules/my-app/...
我也尝试过
npm install -g my-app
但这也不起作用.
如何将模块直接安装到当前目录中?
How can I install the module straight into the current directory?
推荐答案
仅当要使用该软件包作为命令时,才应使用 You should only use 就像全局变量如何是总值一样,但也是必需的
在某些情况下,全局软件包很重要,但最好避免使用
需要. Just like how global variables are kind of gross, but also necessary
in some cases, global packages are important, but best avoided if not
needed. 通常,经验法则是:
npm不会将软件包的文件直接安装到当前目录中. npm will not install a package's files directly into the current directory. 但是,这实际上是一件好事.它将依赖项的文件与您的应用程序分开,并且当您 However, this is actually a good thing. It keeps dependencies' files separate from your app, and Node automatically searches the 这篇关于当前目录中的npm install模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!npm install
安装软件包
npm
在当前目录中查找一个名为node_modules
的现有文件夹,并为该文件夹中安装的每个软件包创建一个文件夹.如果在这里找不到现有的node_modules
文件夹,则它将浏览当前目录的祖先,直到找到一个.如果找不到,则会在当前目录中创建一个.-g
(全局)选项,则程序包将安装在全局位置.该位置因Linux发行版而异,但是/usr/local/lib/node_modules/packagename
是一个示例. CentOS7使用/usr/lib/node_modules/packagename
.
npm
looks for an existing folder called node_modules
in the current directory and creates a folder for each package you install in that folder. If it can't find an existing node_modules
folder here, it then looks through the current directory's ancestors until it finds one. If it can't find one, it creates one in the current directory.-g
(global) option, the package is installed in a global location. This location varies per Linux distribution, but /usr/local/lib/node_modules/packagename
is one example. CentOS7 uses /usr/lib/node_modules/packagename
.-g
.-g
when the package is something you'd want to use as a command.
require('whatever')
,然后将其安装在本地
您的项目.PATH
环境变量中.
require('whatever')
, then install it locally, at the root of
your project.PATH
environment variable.node_modules
folder when you require
something.