summaryrefslogtreecommitdiff
path: root/deps/npm/man/man3/npm.3
blob: a27078deb1cacc2d58e8de624f486c6722aa560f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
.TH "NPM" "3" "June 2015" "" ""
.SH "NAME"
\fBnpm\fR \- javascript package manager
.SH SYNOPSIS
.P
.RS 2
.nf
var npm = require("npm")
npm\.load([configObject, ]function (er, npm) {
  // use the npm object, now that it's loaded\.

  npm\.config\.set(key, val)
  val = npm\.config\.get(key)

  console\.log("prefix = %s", npm\.prefix)

  npm\.commands\.install(["package"], cb)
})
.fi
.RE
.SH VERSION
.P
2.11.3
.SH DESCRIPTION
.P
This is the API documentation for npm\.
To find documentation of the command line
client, see npm help \fBnpm\fR\|\.
.P
Prior to using npm's commands, \fBnpm\.load()\fR must be called\.  If you provide
\fBconfigObject\fR as an object map of top\-level configs, they override the values
stored in the various config locations\. In the npm command line client, this
set of configs is parsed from the command line options\. Additional
configuration params are loaded from two configuration files\. See
npm help \fBnpm\-config\fR, npm help 7 \fBnpm\-config\fR, and npm help 5 \fBnpmrc\fR for more information\.
.P
After that, each of the functions are accessible in the
commands object: \fBnpm\.commands\.<cmd>\fR\|\.  See npm help 7 \fBnpm\-index\fR for a list of
all possible commands\.
.P
All commands on the command object take an \fBarray\fR of positional argument
\fBstrings\fR\|\. The last argument to any function is a callback\. Some
commands take other optional arguments\.
.P
Configs cannot currently be set on a per function basis, as each call to
npm\.config\.set will change the value for \fIall\fR npm commands in that process\.
.P
To find API documentation for a specific command, run the \fBnpm apihelp\fR
command\.
.SH METHODS AND PROPERTIES
.RS 0
.IP \(bu 2
\fBnpm\.load(configs, cb)\fR
  Load the configuration params, and call the \fBcb\fR function once the
  globalconfig and userconfig files have been loaded as well, or on
  nextTick if they've already been loaded\.
.IP \(bu 2
\fBnpm\.config\fR
  An object for accessing npm configuration parameters\.
.RS 0
.IP \(bu 2
\fBnpm\.config\.get(key)\fR
.IP \(bu 2
\fBnpm\.config\.set(key, val)\fR
.IP \(bu 2
\fBnpm\.config\.del(key)\fR

.RE
.IP \(bu 2
\fBnpm\.dir\fR or \fBnpm\.root\fR
  The \fBnode_modules\fR directory where npm will operate\.
.IP \(bu 2
\fBnpm\.prefix\fR
  The prefix where npm is operating\.  (Most often the current working
  directory\.)
.IP \(bu 2
\fBnpm\.cache\fR
  The place where npm keeps JSON and tarballs it fetches from the
  registry (or uploads to the registry)\.
.IP \(bu 2
\fBnpm\.tmp\fR
  npm's temporary working directory\.
.IP \(bu 2
\fBnpm\.deref\fR
  Get the "real" name for a command that has either an alias or
  abbreviation\.

.RE
.SH MAGIC
.P
For each of the methods in the \fBnpm\.commands\fR object, a method is added to the
npm object, which takes a set of positional string arguments rather than an
array and a callback\.
.P
If the last argument is a callback, then it will use the supplied
callback\.  However, if no callback is provided, then it will print out
the error or results\.
.P
For example, this would work in a node repl:
.P
.RS 2
.nf
> npm = require("npm")
> npm\.load()  // wait a sec\.\.\.
> npm\.install("dnode", "express")
.fi
.RE
.P
Note that that \fIwon't\fR work in a node program, since the \fBinstall\fR
method will get called before the configuration load is completed\.
.SH ABBREVS
.P
In order to support \fBnpm ins foo\fR instead of \fBnpm install foo\fR, the
\fBnpm\.commands\fR object has a set of abbreviations as well as the full
method names\.  Use the \fBnpm\.deref\fR method to find the real name\.
.P
For example:
.P
.RS 2
.nf
var cmd = npm\.deref("unp") // cmd === "unpublish"
.fi
.RE