| .TH "NPM" "3" "June 2016" "" "" |
| .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.15.8 |
| .SH DESCRIPTION |
| .P |
| This is the API documentation for npm\. |
| To find documentation of the command line |
| client, see npm help \fBnpm\fP\|\. |
| .P |
| Prior to using npm's commands, \fBnpm\.load()\fP must be called\. If you provide |
| \fBconfigObject\fP 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\fP, npm help 7 \fBnpm\-config\fP, and npm help 5 \fBnpmrc\fP for more information\. |
| .P |
| After that, each of the functions are accessible in the |
| commands object: \fBnpm\.commands\.<cmd>\fP\|\. See npm help 7 \fBnpm\-index\fP 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\fP |
| command\. |
| .SH METHODS AND PROPERTIES |
| .RS 0 |
| .IP \(bu 2 |
| \fBnpm\.load(configs, cb)\fP |
| Load the configuration params, and call the \fBcb\fP 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\fP |
| An object for accessing npm configuration parameters\. |
| .RS 0 |
| .IP \(bu 2 |
| \fBnpm\.config\.get(key)\fP |
| .IP \(bu 2 |
| \fBnpm\.config\.set(key, val)\fP |
| .IP \(bu 2 |
| \fBnpm\.config\.del(key)\fP |
| |
| .RE |
| .IP \(bu 2 |
| \fBnpm\.dir\fP or \fBnpm\.root\fP |
| The \fBnode_modules\fP directory where npm will operate\. |
| .IP \(bu 2 |
| \fBnpm\.prefix\fP |
| The prefix where npm is operating\. (Most often the current working |
| directory\.) |
| .IP \(bu 2 |
| \fBnpm\.cache\fP |
| The place where npm keeps JSON and tarballs it fetches from the |
| registry (or uploads to the registry)\. |
| .IP \(bu 2 |
| \fBnpm\.tmp\fP |
| npm's temporary working directory\. |
| .IP \(bu 2 |
| \fBnpm\.deref\fP |
| 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\fP 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\fP |
| method will get called before the configuration load is completed\. |
| .SH ABBREVS |
| .P |
| In order to support \fBnpm ins foo\fP instead of \fBnpm install foo\fP, the |
| \fBnpm\.commands\fP object has a set of abbreviations as well as the full |
| method names\. Use the \fBnpm\.deref\fP method to find the real name\. |
| .P |
| For example: |
| .P |
| .RS 2 |
| .nf |
| var cmd = npm\.deref("unp") // cmd === "unpublish" |
| .fi |
| .RE |
| |