4 <meta http-equiv="content-type" value="text/html;utf-8">
5 <link rel="stylesheet" type="text/css" href="../../static/style.css">
9 <h1><a href="../api/npm.html">npm</a></h1> <p>node package manager</p>
11 <h2 id="SYNOPSIS">SYNOPSIS</h2>
13 <pre><code>var npm = require("npm")
14 npm.load([configObject], function (er, npm) {
15 // use the npm object, now that it's loaded.
17 npm.config.set(key, val)
18 val = npm.config.get(key)
20 console.log("prefix = %s", npm.prefix)
22 npm.commands.install(["package"], cb)
25 <h2 id="VERSION">VERSION</h2>
29 <h2 id="DESCRIPTION">DESCRIPTION</h2>
31 <p>This is the API documentation for npm.
32 To find documentation of the command line
33 client, see <code><a href="../cli/npm.html">npm(1)</a></code>.</p>
35 <p>Prior to using npm'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="../cli/npm-config.html">npm-config(1)</a></code>,
41 <code><a href="../misc/npm-config.html">npm-config(7)</a></code>, and <code><a href="../files/npmrc.html">npmrc(5)</a></code> for more information.</p>
43 <p>After that, each of the functions are accessible in the
44 commands object: <code>npm.commands.<cmd></code>. See <code><a href="../misc/npm-index.html">npm-index(7)</a></code> for a list of
45 all possible commands.</p>
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>
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>
54 <p>To find API documentation for a specific command, run the <code>npm apihelp</code>
57 <h2 id="METHODS-AND-PROPERTIES">METHODS AND PROPERTIES</h2>
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'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's temporary working directory.</p></li><li><p><code>npm.deref</code></p><p>Get the "real" name for a command that has either an alias or
64 abbreviation.</p></li></ul>
66 <h2 id="MAGIC">MAGIC</h2>
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>
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>
76 <p>For example, this would work in a node repl:</p>
78 <pre><code>> npm = require("npm")
79 > npm.load() // wait a sec...
80 > npm.install("dnode", "express")</code></pre>
82 <p>Note that that <em>won't</em> work in a node program, since the <code>install</code>
83 method will get called before the configuration load is completed.</p>
85 <h2 id="ABBREVS">ABBREVS</h2>
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>
93 <pre><code>var cmd = npm.deref("unp") // cmd === "unpublish"</code></pre>
95 <p id="footer">npm — npm@1.3.15</p>
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]/)
106 , toc = document.createElement("ul")
107 toc.innerHTML = els.map(function (el) {
108 var i = el.tagName.charAt(1)
118 out += "<li><a href='#" + el.id + "'>" +
119 ( el.innerText || el.text || el.innerHTML)
124 document.body.appendChild(toc)