<h2id="Why-can-t-npm-just-put-everything-in-one-place-like-other-package-managers">Why can't npm just put everything in one place, like other package managers?</h2>
<ul><li>a) a folder containing a program described by a package.json file</li><li>b) a gzipped tarball containing (a)</li><li>c) a url that resolves to (b)</li><li>d) a <code><name>@<version></code> that is published on the registry with (c)</li><li>e) a <code><name>@<tag></code> that points to (d)</li><li>f) a <code><name></code> that has a "latest" tag satisfying (e)</li><li>g) a <code>git</code> url that, when cloned, results in (a).</li></ul>
<h2id="What-is-a-module">What is a <code>module</code>?</h2>
<p>A module is anything that can be loaded with <code>require()</code> in a Node.js
program. The following things are all examples of things that can be
loaded as modules:</p>
<ul><li>A folder with a <code>package.json</code> file containing a <code>main</code> field.</li><li>A folder with an <code>index.js</code> file in it.</li><li>A JavaScript file.</li></ul>
<p>Most npm packages are modules, because they are libraries that you
load with <code>require</code>. However, there's no requirement that an npm
package be a module! Some only contain an executable command-line
interface, and don't provide a <code>main</code> field for use in Node programs.</p>
<p>Almost all npm packages (at least, those that are Node programs)
<em>contain</em> many modules within them (because every file they load with
<code>require()</code> is a module).</p>
<p>In the context of a Node program, the <code>module</code> is also the thing that
was loaded <em>from</em> a file. For example, in the following program:</p>
<p>we might say that "The variable <code>req</code> refers to the <code>request</code> module".</p>
<h2id="So-why-is-it-the-node_modules-folder-but-package-json-file-Why-not-node_packages-or-module-json">So, why is it the "<code>node_modules</code>" folder, but "<code>package.json</code>" file? Why not <code>node_packages</code> or <code>module.json</code>?</h2>
<p>The <code>package.json</code> file defines the package. (See "What is a
package?" above.)</p>
<p>The <code>node_modules</code> folder is the place Node.js looks for modules.
(See "What is a module?" above.)</p>
<p>For example, if you create a file at <code>node_modules/foo.js</code> and then
had a program that did <code>var f = require('foo.js')</code> then it would load
the module. However, <code>foo.js</code> is not a "package" in this case,
because it does not have a package.json.</p>
<p>Alternatively, if you create a package which does not have an
<code>index.js</code> or a <code>"main"</code> field in the <code>package.json</code> file, then it is
not a module. Even if it's installed in <code>node_modules</code>, it can't be
an argument to <code>require()</code>.</p>
<h2id="node_modules-is-the-name-of-my-deity-s-arch-rival-and-a-Forbidden-Word-in-my-religion-Can-I-configure-npm-to-use-a-different-folder"><code>"node_modules"</code> is the name of my deity's arch-rival, and a Forbidden Word in my religion. Can I configure npm to use a different folder?</h2>
<p>No. This will never happen. This question comes up sometimes,
because it seems silly from the outside that npm couldn't just be
configured to put stuff somewhere else, and then npm could load them
from there. It's an arbitrary spelling choice, right? What's the big
deal?</p>
<p>At the time of this writing, the string <code>'node_modules'</code> appears 151
times in 53 separate files in npm and node core (excluding tests and
documentation).</p>
<p>Some of these references are in node's built-in module loader. Since
npm is not involved <strong>at all</strong> at run-time, node itself would have to
be configured to know where you've decided to stick stuff. Complexity
hurdle #1. Since the Node module system is locked, this cannot be
changed, and is enough to kill this request. But I'll continue, in
deference to your deity's delicate feelings regarding spelling.</p>
<p>Many of the others are in dependencies that npm uses, which are not
necessarily tightly coupled to npm (in the sense that they do not read
npm's configuration files, etc.) Each of these would have to be
configured to take the name of the <code>node_modules</code> folder as a
parameter. Complexity hurdle #2.</p>
<p>Furthermore, npm has the ability to "bundle" dependencies by adding
the dep names to the <code>"bundledDependencies"</code> list in package.json,
which causes the folder to be included in the package tarball. What
if the author of a module bundles its dependencies, and they use a
different spelling for <code>node_modules</code>? npm would have to rename the
folder at publish time, and then be smart enough to unpack it using
your locally configured name. Complexity hurdle #3.</p>
<p>Furthermore, what happens when you <em>change</em> this name? Fine, it's
easy enough the first time, just rename the <code>node_modules</code> folders to
<code>./blergyblerp/</code> or whatever name you choose. But what about when you
change it again? npm doesn't currently track any state about past
configuration settings, so this would be rather difficult to do
properly. It would have to track every previous value for this
config, and always accept any of them, or else yesterday's install may
be broken tomorrow. Complexity hurdle #5.</p>
<p>Never going to happen. The folder is named <code>node_modules</code>. It is
written indelibly in the Node Way, handed down from the ancient times
<p>See <code><ahref="../misc/npm-developers.html">npm-developers(7)</a></code> and <code><ahref="../files/package.json.html">package.json(5)</a></code>.</p>
<h2id="How-do-I-symlink-to-a-dev-folder-so-I-don-t-have-to-keep-re-installing">How do I symlink to a dev folder so I don't have to keep re-installing?</h2>
<h2id="I-have-a-question-or-request-not-addressed-here-Where-should-I-put-it">I have a question or request not addressed here. Where should I put it?</h2>