NPM(3)
π NAME π β NPM(3), the javascript package manager API
npmβ javascript package manager π
okay so this is NPM(3), bestie β the API manual, not the CLI manual. for the command line client docs, see npm help npm. π
β¨ SYNOPSIS β¨
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)
})
π VERSION π
2.15.12 β that's the version this page is serving, no cap. π«Ά
π¦ DESCRIPTION π¦
okay so this is the API documentation for npm. to find documentation of the command line client, see npm help npm. π
prior to using npm's commands, npm.load() must be called. literally must. if you provide configObject as an object map of top-level configs, those 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 npm-config, npm help 7 npm-config, and npm help 5 npmrc for more information. iykyk. β¨
after that, each of the functions is accessible in the commands object: npm.commands.<cmd>. see npm help 7 npm-index for a list of all possible commands. π
all commands on the command object take an array of positional argument strings. the last argument to any function is a callback. some commands take other optional arguments. periodt.
configs cannot currently be set on a per function basis, bestie π β as each call to npm.config.set will change the value for all npm commands in that process. no cap.
to find API documentation for a specific command, run the npm apihelp command. slay. πΈ
π METHODS AND PROPERTIES π
here's the whole cast β main character energy only. π
npm.load(configs, cb)β load the configuration params, and call thecbfunction once theglobalconfiganduserconfigfiles have been loaded as well, or onnextTickif they've already been loaded. πnpm.configβ an object for accessing npm configuration parameters. the config plug, basically. πnpm.config.get(key)β the get call, signature literallynpm.config.get(key). πnpm.config.set(key, val)β the set call, signature literallynpm.config.set(key, val). β¨npm.config.del(key)β the delete call, signature literallynpm.config.del(key). π«Άnpm.dirornpm.rootβ thenode_modulesdirectory where npm will operate. πnpm.prefixβ the prefix where npm is operating. (most often the current working directory.) πnpm.cacheβ the place where npm keeps JSON and tarballs it fetches from the registry (or uploads to the registry). ποΈnpm.tmpβ npm's temporary working directory. π§npm.derefβ get the "real" name for a command that has either an alias or abbreviation. π
π₯ MAGIC π₯
for each of the methods in the npm.commands object, a method is added to the npm object, which takes a set of positional string arguments rather than an array and a callback. it's giving built-in convenience. β¨
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. π
for example, this would work in a node repl:
> npm = require("npm")
> npm.load() // wait a sec...
> npm.install("dnode", "express")
note that that won't work in a node program, since the install method will get called before the configuration load is completed. π
π ABBREVS π
in order to support npm ins foo instead of npm install foo, the npm.commands object has a set of abbreviations as well as the full method names. use the npm.deref method to find the real name. π΅οΈββοΈ
for example:
var cmd = npm.deref("unp") // cmd === "unpublish"
that's the whole NPM(3) API tea, bestie βπ β source/version: NPM(3), version 2.15.12, dated March 2017. periodt. π«Ά
π¦ where this page comes from
- nixos 26.05: hueadm 1.2.1
- nixpkgs unstable: hueadm 1.2.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms