The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / deps / npm / doc / api / npm.md @ 5aef65a9
History | View | Annotate | Download (3.2 KB)
1 |
npm(3) -- node package manager |
---|---|
2 |
============================== |
3 |
|
4 |
## SYNOPSIS |
5 |
|
6 |
var npm = require("npm") |
7 |
npm.load([configObject,] function (er, npm) { |
8 |
// use the npm object, now that it's loaded. |
9 |
|
10 |
npm.config.set(key, val) |
11 |
val = npm.config.get(key) |
12 |
|
13 |
console.log("prefix = %s", npm.prefix) |
14 |
|
15 |
npm.commands.install(["package"], cb) |
16 |
}) |
17 |
|
18 |
## VERSION |
19 |
|
20 |
@VERSION@ |
21 |
|
22 |
## DESCRIPTION |
23 |
|
24 |
This is the API documentation for npm. |
25 |
To find documentation of the command line |
26 |
client, see `npm(1)`. |
27 |
|
28 |
Prior to using npm's commands, `npm.load()` must be called. |
29 |
If you provide `configObject` as an object hash of top-level |
30 |
configs, they override the values stored in the various config |
31 |
locations. In the npm command line client, this set of configs |
32 |
is parsed from the command line options. Additional configuration |
33 |
params are loaded from two configuration files. See `npm-config(1)` |
34 |
for more information. |
35 |
|
36 |
After that, each of the functions are accessible in the |
37 |
commands object: `npm.commands.<cmd>`. See `npm-index(1)` for a list of |
38 |
all possible commands. |
39 |
|
40 |
All commands on the command object take an **array** of positional argument |
41 |
**strings**. The last argument to any function is a callback. Some |
42 |
commands take other optional arguments. |
43 |
|
44 |
Configs cannot currently be set on a per function basis, as each call to |
45 |
npm.config.set will change the value for *all* npm commands in that process. |
46 |
|
47 |
To find API documentation for a specific command, run the `npm apihelp` |
48 |
command. |
49 |
|
50 |
## METHODS AND PROPERTIES |
51 |
|
52 |
* `npm.load(configs, cb)` |
53 |
|
54 |
Load the configuration params, and call the `cb` function once the |
55 |
globalconfig and userconfig files have been loaded as well, or on |
56 |
nextTick if they've already been loaded. |
57 |
|
58 |
* `npm.config` |
59 |
|
60 |
An object for accessing npm configuration parameters. |
61 |
|
62 |
* `npm.config.get(key)` |
63 |
* `npm.config.set(key, val)` |
64 |
* `npm.config.del(key)` |
65 |
|
66 |
* `npm.dir` or `npm.root` |
67 |
|
68 |
The `node_modules` directory where npm will operate. |
69 |
|
70 |
* `npm.prefix` |
71 |
|
72 |
The prefix where npm is operating. (Most often the current working |
73 |
directory.) |
74 |
|
75 |
* `npm.cache` |
76 |
|
77 |
The place where npm keeps JSON and tarballs it fetches from the |
78 |
registry (or uploads to the registry). |
79 |
|
80 |
* `npm.tmp` |
81 |
|
82 |
npm's temporary working directory. |
83 |
|
84 |
* `npm.deref` |
85 |
|
86 |
Get the "real" name for a command that has either an alias or |
87 |
abbreviation. |
88 |
|
89 |
## MAGIC |
90 |
|
91 |
For each of the methods in the `npm.commands` hash, a method is added to |
92 |
the npm object, which takes a set of positional string arguments rather |
93 |
than an array and a callback. |
94 |
|
95 |
If the last argument is a callback, then it will use the supplied |
96 |
callback. However, if no callback is provided, then it will print out |
97 |
the error or results. |
98 |
|
99 |
For example, this would work in a node repl: |
100 |
|
101 |
> npm = require("npm") |
102 |
> npm.load() // wait a sec... |
103 |
> npm.install("dnode", "express") |
104 |
|
105 |
Note that that *won't* work in a node program, since the `install` |
106 |
method will get called before the configuration load is completed. |
107 |
|
108 |
## ABBREVS |
109 |
|
110 |
In order to support `npm ins foo` instead of `npm install foo`, the |
111 |
`npm.commands` object has a set of abbreviations as well as the full |
112 |
method names. Use the `npm.deref` method to find the real name. |
113 |
|
114 |
For example: |
115 |
|
116 |
var cmd = npm.deref("unp") // cmd === "unpublish" |