1 npm-faq(7) -- Frequently Asked Questions
2 ========================================
4 ## Where can I find these docs in HTML?
6 <https://npmjs.org/doc/>, or run:
8 npm config set viewer browser
10 to open these documents in your default web browser rather than `man`.
14 That's not really a question.
16 ## Why didn't it work?
20 Read the error output, and if you can't figure out what it means,
21 do what it says and post a bug with all the information it asks for.
23 ## Where does npm put stuff?
29 * Use the `npm root` command to see where modules go, and the `npm bin`
30 command to see where executables go
31 * Global installs are different from local installs. If you install
32 something with the `-g` flag, then its executables go in `npm bin -g`
33 and its modules go in `npm root -g`.
35 ## How do I install something on my computer in a central location?
37 Install it globally by tacking `-g` or `--global` to the command. (This
38 is especially important for command line utilities that need to add
39 their bins to the global system `PATH`.)
41 ## I installed something globally, but I can't `require()` it
45 The global install location is a place for command-line utilities
46 to put their bins in the system `PATH`. It's not for use with `require()`.
48 If you `require()` a module in your code, then that means it's a
49 dependency, and a part of your program. You need to install it locally
52 ## Why can't npm just put everything in one place, like other package managers?
54 Not every change is an improvement, but every improvement is a change.
55 This would be like asking git to do network IO for every commit. It's
56 not going to happen, because it's a terrible idea that causes more
57 problems than it solves.
59 It is much harder to avoid dependency conflicts without nesting
60 dependencies. This is fundamental to the way that npm works, and has
61 proven to be an extremely successful approach. See `npm-folders(5)` for
64 If you want a package to be installed in one place, and have all your
65 programs reference the same copy of it, then use the `npm link` command.
66 That's what it's for. Install it globally, then link it into each
69 ## Whatever, I really want the old style 'everything global' style.
71 Write your own package manager, then. It's not that hard.
73 npm will not help you do something that is known to be a bad idea.
75 ## Should I check my `node_modules` folder into git?
77 Mikeal Rogers answered this question very well:
79 <http://www.mikealrogers.com/posts/nodemodules-in-git.html>
83 * Check `node_modules` into git for things you **deploy**, such as
85 * Do not check `node_modules` into git for libraries and modules
86 intended to be reused.
87 * Use npm to manage dependencies in your dev environment, but not in
88 your deployment scripts.
90 ## Is it 'npm' or 'NPM' or 'Npm'?
92 npm should never be capitalized unless it is being displayed in a
93 location that is customarily all-caps (such as the title of man pages.)
95 ## If 'npm' is an acronym, why is it never capitalized?
97 Contrary to the belief of many, "npm" is not in fact an abbreviation for
98 "Node Package Manager". It is a recursive bacronymic abbreviation for
99 "npm is not an acronym". (If it was "ninaa", then it would be an
100 acronym, and thus incorrectly named.)
102 "NPM", however, *is* an acronym (more precisely, a capitonym) for the
103 National Association of Pastoral Musicians. You can learn more
104 about them at <http://npm.org/>.
106 In software, "NPM" is a Non-Parametric Mapping utility written by
107 Chris Rorden. You can analyze pictures of brains with it. Learn more
108 about the (capitalized) NPM program at <http://www.cabiatl.com/mricro/npm/>.
110 The first seed that eventually grew into this flower was a bash utility
111 named "pm", which was a shortened descendent of "pkgmakeinst", a
112 bash function that was used to install various different things on different
113 platforms, most often using Yahoo's `yinst`. If `npm` was ever an
114 acronym for anything, it was `node pm` or maybe `new pm`.
116 So, in all seriousness, the "npm" project is named after its command-line
117 utility, which was organically selected to be easily typed by a right-handed
118 programmer using a US QWERTY keyboard layout, ending with the
119 right-ring-finger in a postition to type the `-` key for flags and
120 other command-line arguments. That command-line utility is always
121 lower-case, though it starts most sentences it is a part of.
123 ## How do I list installed packages?
127 ## How do I search for packages?
131 Arguments are greps. `npm search jsdom` shows jsdom packages.
133 ## How do I update npm?
137 You can also update all outdated local packages by doing `npm update` without
138 any arguments, or global packages by doing `npm update -g`.
140 Occasionally, the version of npm will progress such that the current
141 version cannot be properly installed with the version that you have
142 installed already. (Consider, if there is ever a bug in the `update`
145 In those cases, you can do this:
147 curl https://npmjs.org/install.sh | sh
149 ## What is a `package`?
153 * a) a folder containing a program described by a package.json file
154 * b) a gzipped tarball containing (a)
155 * c) a url that resolves to (b)
156 * d) a `<name>@<version>` that is published on the registry with (c)
157 * e) a `<name>@<tag>` that points to (d)
158 * f) a `<name>` that has a "latest" tag satisfying (e)
159 * g) a `git` url that, when cloned, results in (a).
161 Even if you never publish your package, you can still get a lot of
162 benefits of using npm if you just want to write a node program (a), and
163 perhaps if you also want to be able to easily install it elsewhere
164 after packing it up into a tarball (b).
166 Git urls can be of the form:
168 git://github.com/user/project.git#commit-ish
169 git+ssh://user@hostname:project.git#commit-ish
170 git+http://user@hostname/project/blah.git#commit-ish
171 git+https://user@hostname/project/blah.git#commit-ish
173 The `commit-ish` can be any tag, sha, or branch which can be supplied as
174 an argument to `git checkout`. The default is `master`.
176 ## What is a `module`?
178 A module is anything that can be loaded with `require()` in a Node.js
179 program. The following things are all examples of things that can be
182 * A folder with a `package.json` file containing a `main` field.
183 * A folder with an `index.js` file in it.
186 Most npm packages are modules, because they are libraries that you
187 load with `require`. However, there's no requirement that an npm
188 package be a module! Some only contain an executable command-line
189 interface, and don't provide a `main` field for use in Node programs.
191 Almost all npm packages (at least, those that are Node programs)
192 *contain* many modules within them (because every file they load with
193 `require()` is a module).
195 In the context of a Node program, the `module` is also the thing that
196 was loaded *from* a file. For example, in the following program:
198 var req = require('request')
200 we might say that "The variable `req` refers to the `request` module".
202 ## So, why is it the "`node_modules`" folder, but "`package.json`" file? Why not `node_packages` or `module.json`?
204 The `package.json` file defines the package. (See "What is a
207 The `node_modules` folder is the place Node.js looks for modules.
208 (See "What is a module?" above.)
210 For example, if you create a file at `node_modules/foo.js` and then
211 had a program that did `var f = require('foo.js')` then it would load
212 the module. However, `foo.js` is not a "package" in this case,
213 because it does not have a package.json.
215 Alternatively, if you create a package which does not have an
216 `index.js` or a `"main"` field in the `package.json` file, then it is
217 not a module. Even if it's installed in `node_modules`, it can't be
218 an argument to `require()`.
220 ## `"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?
222 No. This will never happen. This question comes up sometimes,
223 because it seems silly from the outside that npm couldn't just be
224 configured to put stuff somewhere else, and then npm could load them
225 from there. It's an arbitrary spelling choice, right? What's the big
228 At the time of this writing, the string `'node_modules'` appears 151
229 times in 53 separate files in npm and node core (excluding tests and
232 Some of these references are in node's built-in module loader. Since
233 npm is not involved **at all** at run-time, node itself would have to
234 be configured to know where you've decided to stick stuff. Complexity
235 hurdle #1. Since the Node module system is locked, this cannot be
236 changed, and is enough to kill this request. But I'll continue, in
237 deference to your deity's delicate feelings regarding spelling.
239 Many of the others are in dependencies that npm uses, which are not
240 necessarily tightly coupled to npm (in the sense that they do not read
241 npm's configuration files, etc.) Each of these would have to be
242 configured to take the name of the `node_modules` folder as a
243 parameter. Complexity hurdle #2.
245 Furthermore, npm has the ability to "bundle" dependencies by adding
246 the dep names to the `"bundledDependencies"` list in package.json,
247 which causes the folder to be included in the package tarball. What
248 if the author of a module bundles its dependencies, and they use a
249 different spelling for `node_modules`? npm would have to rename the
250 folder at publish time, and then be smart enough to unpack it using
251 your locally configured name. Complexity hurdle #3.
253 Furthermore, what happens when you *change* this name? Fine, it's
254 easy enough the first time, just rename the `node_modules` folders to
255 `./blergyblerp/` or whatever name you choose. But what about when you
256 change it again? npm doesn't currently track any state about past
257 configuration settings, so this would be rather difficult to do
258 properly. It would have to track every previous value for this
259 config, and always accept any of them, or else yesterday's install may
260 be broken tomorrow. Complexity hurdle #5.
262 Never going to happen. The folder is named `node_modules`. It is
263 written indelibly in the Node Way, handed down from the ancient times
266 ## How do I install node with npm?
268 You don't. Try one of these node version managers:
272 * <http://github.com/isaacs/nave>
273 * <http://github.com/visionmedia/n>
274 * <http://github.com/creationix/nvm>
278 * <http://github.com/marcelklehr/nodist>
279 * <https://github.com/hakobera/nvmw>
281 ## How can I use npm for development?
283 See `npm-developers(7)` and `package.json(5)`.
285 You'll most likely want to `npm link` your development folder. That's
288 To set up your own private registry, check out `npm-registry(7)`.
290 ## Can I list a url as a dependency?
292 Yes. It should be a url to a gzipped tarball containing a single folder
293 that has a package.json in its root, or a git url.
294 (See "what is a package?" above.)
296 ## How do I symlink to a dev folder so I don't have to keep re-installing?
300 ## The package registry website. What is that exactly?
302 See `npm-registry(7)`.
304 ## I forgot my password, and can't publish. How do I reset it?
306 Go to <https://npmjs.org/forgot>.
308 ## I get ECONNREFUSED a lot. What's up?
310 Either the registry is down, or node's DNS isn't able to reach out.
312 To check if the registry is down, open up <http://registry.npmjs.org/>
313 in a web browser. This will also tell you if you are just unable to
314 access the internet for some reason.
316 If the registry IS down, let me know by emailing <i@izs.me> or posting
317 an issue at <https://github.com/isaacs/npm/issues>. We'll have
318 someone kick it or something.
320 ## Why no namespaces?
322 Please see this discussion: <https://github.com/isaacs/npm/issues/798>
324 tl;dr - It doesn't actually make things better, and can make them worse.
326 If you want to namespace your own packages, you may: simply use the
327 `-` character to separate the names. npm is a mostly anarchic system.
328 There is not sufficient need to impose namespace rules on everyone.
332 `npm view npm author`
334 `npm view npm contributors`
336 ## I have a question or request not addressed here. Where should I put it?
338 Post an issue on the github project:
340 * <https://github.com/isaacs/npm/issues>
342 ## Why does npm hate me?
344 npm is not capable of hatred. It loves everyone, especially you.