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%
pm
. 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.