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.

Statistics
| Branch: | Revision:

main_repo / deps / npm / html / api / npm.html @ 5aef65a9

History | View | Annotate | Download (5.02 KB)

1
<!doctype html>
2
<html>
3
  <title>npm</title>
4
  <meta http-equiv="content-type" value="text/html;utf-8">
5
  <link rel="stylesheet" type="text/css" href="../static/style.css">
6

    
7
  <body>
8
    <div id="wrapper">
9
<h1><a href="../api/npm.html">npm</a></h1> <p>node package manager</p>
10

    
11
<h2 id="SYNOPSIS">SYNOPSIS</h2>
12

    
13
<pre><code>var npm = require(&quot;npm&quot;)
14
npm.load([configObject,] function (er, npm) {
15
  // use the npm object, now that it&#39;s loaded.
16

    
17
  npm.config.set(key, val)
18
  val = npm.config.get(key)
19

    
20
  console.log(&quot;prefix = %s&quot;, npm.prefix)
21

    
22
  npm.commands.install([&quot;package&quot;], cb)
23
})</code></pre>
24

    
25
<h2 id="VERSION">VERSION</h2>
26

    
27
<p>1.2.10</p>
28

    
29
<h2 id="DESCRIPTION">DESCRIPTION</h2>
30

    
31
<p>This is the API documentation for npm.
32
To find documentation of the command line
33
client, see <code><a href="../doc/npm.html">npm(1)</a></code>.</p>
34

    
35
<p>Prior to using npm&#39;s commands, <code>npm.load()</code> must be called.
36
If you provide <code>configObject</code> as an object hash of top-level
37
configs, they override the values stored in the various config
38
locations. In the npm command line client, this set of configs
39
is parsed from the command line options. Additional configuration
40
params are loaded from two configuration files. See <code><a href="../doc/config.html">config(1)</a></code>
41
for more information.</p>
42

    
43
<p>After that, each of the functions are accessible in the
44
commands object: <code>npm.commands.&lt;cmd&gt;</code>.  See <code><a href="../doc/index.html">index(1)</a></code> for a list of
45
all possible commands.</p>
46

    
47
<p>All commands on the command object take an <strong>array</strong> of positional argument
48
<strong>strings</strong>. The last argument to any function is a callback. Some
49
commands take other optional arguments.</p>
50

    
51
<p>Configs cannot currently be set on a per function basis, as each call to
52
npm.config.set will change the value for <em>all</em> npm commands in that process.</p>
53

    
54
<p>To find API documentation for a specific command, run the <code>npm apihelp</code>
55
command.</p>
56

    
57
<h2 id="METHODS-AND-PROPERTIES">METHODS AND PROPERTIES</h2>
58

    
59
<ul><li><p><code>npm.load(configs, cb)</code></p><p>Load the configuration params, and call the <code>cb</code> function once the
60
globalconfig and userconfig files have been loaded as well, or on
61
nextTick if they&#39;ve already been loaded.</p></li><li><p><code>npm.config</code></p><p>An object for accessing npm configuration parameters.</p><ul><li><p><code>npm.config.get(key)</code></p></li><li><code>npm.config.set(key, val)</code></li><li><p><code>npm.config.del(key)</code></p></li></ul></li><li><p><code>npm.dir</code> or <code>npm.root</code></p><p>The <code>node_modules</code> directory where npm will operate.</p></li><li><p><code>npm.prefix</code></p><p>The prefix where npm is operating.  (Most often the current working
62
directory.)</p></li><li><p><code>npm.cache</code></p><p>The place where npm keeps JSON and tarballs it fetches from the
63
registry (or uploads to the registry).</p></li><li><p><code>npm.tmp</code></p><p>npm&#39;s temporary working directory.</p></li><li><p><code>npm.deref</code></p><p>Get the &quot;real&quot; name for a command that has either an alias or
64
abbreviation.</p></li></ul>
65

    
66
<h2 id="MAGIC">MAGIC</h2>
67

    
68
<p>For each of the methods in the <code>npm.commands</code> hash, a method is added to
69
the npm object, which takes a set of positional string arguments rather
70
than an array and a callback.</p>
71

    
72
<p>If the last argument is a callback, then it will use the supplied
73
callback.  However, if no callback is provided, then it will print out
74
the error or results.</p>
75

    
76
<p>For example, this would work in a node repl:</p>
77

    
78
<pre><code>&gt; npm = require(&quot;npm&quot;)
79
&gt; npm.load()  // wait a sec...
80
&gt; npm.install(&quot;dnode&quot;, &quot;express&quot;)</code></pre>
81

    
82
<p>Note that that <em>won&#39;t</em> work in a node program, since the <code>install</code>
83
method will get called before the configuration load is completed.</p>
84

    
85
<h2 id="ABBREVS">ABBREVS</h2>
86

    
87
<p>In order to support <code>npm ins foo</code> instead of <code>npm install foo</code>, the
88
<code>npm.commands</code> object has a set of abbreviations as well as the full
89
method names.  Use the <code>npm.deref</code> method to find the real name.</p>
90

    
91
<p>For example:</p>
92

    
93
<pre><code>var cmd = npm.deref(&quot;unp&quot;) // cmd === &quot;unpublish&quot;</code></pre>
94
</div>
95
<p id="footer">npm &mdash; npm@1.2.10</p>
96
<script>
97
;(function () {
98
var wrapper = document.getElementById("wrapper")
99
var els = Array.prototype.slice.call(wrapper.getElementsByTagName("*"), 0)
100
  .filter(function (el) {
101
    return el.parentNode === wrapper
102
        && el.tagName.match(/H[1-6]/)
103
        && el.id
104
  })
105
var l = 2
106
  , toc = document.createElement("ul")
107
toc.innerHTML = els.map(function (el) {
108
  var i = el.tagName.charAt(1)
109
    , out = ""
110
  while (i > l) {
111
    out += "<ul>"
112
    l ++
113
  }
114
  while (i < l) {
115
    out += "</ul>"
116
    l --
117
  }
118
  out += "<li><a href='#" + el.id + "'>" +
119
    ( el.innerText || el.text || el.innerHTML)
120
    + "</a>"
121
  return out
122
}).join("\n")
123
toc.id = "toc"
124
document.body.appendChild(toc)
125
})()
126
</script>
127
</body></html>