npm-folders
https://docs.npmjs.com/configuring-npm/folders.html
npm puts various things on your computer. That’s its job.
This document will tell you what it puts where.
tl;dr
- Local install (default): puts stuff in
./node_modules
of the current package root. - Global install (with
-g
): puts stuff in /usr/local or wherever node is installed. - Install it locally if you’re going to
require()
it. - Install it globally if you’re going to run it on the command line.
- If you need both, then install it in both places, or use
npm link
.
prefix Configuration
The prefix
config defaults to the location where node is installed. On most systems, this is /usr/local
. On Windows, it’s %AppData%\npm
. On Unix systems, it’s one level up, since node is typically installed at {prefix}/bin/node
rather than {prefix}/node.exe
.
When the global
flag is set, npm installs things into this prefix. When it is not set, it uses the root of the current package, or the current working directory if not in a package already.
Node Modules
Packages are dropped into the node_modules
folder under the prefix
. When installing locally, this means that you can require("packagename")
to load its main module, or require("packagename/lib/path/to/sub/module")
to load other modules.
Global installs on Unix systems go to {prefix}/lib/node_modules
. Global installs on Windows go to {prefix}/node_modules
(that is, no lib
folder.)
Scoped packages are installed the same way, except they are grouped together in a sub-folder of the relevant node_modules
folder with the name of that scope prefix by the @ symbol, e.g. npm install @myorg/package
would place the package in {prefix}/node_modules/@myorg/package
. See scope
for more details.
If you wish to require()
a package, then install it locally.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2018-05-19 What is an ISAPI Extension?
2017-05-19 Windows cannot find ". Make sure you typed the name correctly, and then try again
2017-05-19 Gitblit从一个服务器,迁移到另外一个服务器
2017-05-19 Firefox访问https的网站,一直提示不安全
2015-05-19 TeeChart 3D 显示三维的图形,使用Surface
2015-05-19 TeeChart的X轴为时间,多个Y轴的显示