3 The code that npm uses to talk to the registry.
5 It handles all the caching and HTTP calls.
10 var RegClient = require('npm-registry-client')
11 var client = new RegClient(config)
13 client.get("npm", "latest", 1000, function (er, data, raw, res) {
14 // error is an error if there was a problem.
15 // data is the parsed data object
16 // raw is the json string
17 // res is the response from couch
23 This program is designed to work with
24 [npmconf](https://npmjs.org/package/npmconf), but you can also pass in
25 a plain-jane object with the appropriate configs, and it'll shim it
26 for you. Any configuration thingie that has get/set/del methods will
29 * `registry` **Required** {String} URL to the registry
30 * `cache` **Required** {String} Path to the cache folder
31 * `always-auth` {Boolean} Auth even for GET requests.
32 * `auth` {String} A base64-encoded `username:password`
33 * `email` {String} User's email address
34 * `tag` {String} The default tag to use when publishing new packages.
36 * `ca` {String} Cerficate signing authority certificates to trust.
37 * `strict-ssl` {Boolean} Whether or not to be strict with SSL
38 certificates. Default = `true`
39 * `user-agent` {String} User agent header to send. Default =
40 `"node/{process.version}"`
41 * `log` {Object} The logger to use. Defaults to `require("npmlog")` if
42 that works, otherwise logs are disabled.
43 * `fetch-retries` {Number} Number of times to retry on GET failures.
45 * `fetch-retry-factor` {Number} `factor` setting for `node-retry`. Default=10
46 * `fetch-retry-mintimeout` {Number} `minTimeout` setting for `node-retry`.
47 Default=10000 (10 seconds)
48 * `fetch-retry-maxtimeout` {Number} `maxTimeout` setting for `node-retry`.
49 Default=60000 (60 seconds)
50 * `proxy` {URL} The url to proxy requests through.
51 * `https-proxy` {URL} The url to proxy https requests through.
52 Defaults to be the same as `proxy` if unset.
53 * `_auth` {String} The base64-encoded authorization header.
54 * `username` `_password` {String} Username/password to use to generate
55 `_auth` if not supplied.
56 * `_token` {Object} A token for use with
57 [couch-login](https://npmjs.org/package/couch-login)
59 # client.request(method, where, [what], [etag], [nofollow], cb)
61 * `method` {String} HTTP method
62 * `where` {String} Path to request on the server
63 * `what` {Stream | Buffer | String | Object} The request body. Objects
64 that are not Buffers or Streams are encoded as JSON.
65 * `etag` {String} The cached ETag
66 * `nofollow` {Boolean} Prevent following 302/301 responses
68 * `error` {Error | null}
69 * `data` {Object} the parsed data object
70 * `raw` {String} the json
71 * `res` {Response Object} response from couch
73 Make a request to the registry. All the other methods are wrappers
76 # client.adduser(username, password, email, cb)
83 Add a user account to the registry, or verify the credentials.
85 # client.get(url, [timeout], [nofollow], [staleOk], cb)
87 * `url` {String} The url path to fetch
88 * `timeout` {Number} Number of seconds old that a cached copy must be
89 before a new request will be made.
90 * `nofollow` {Boolean} Do not follow 301/302 responses
91 * `staleOk` {Boolean} If there's cached data available, then return that
92 to the callback quickly, and update the cache the background.
94 Fetches data from the registry via a GET request, saving it in
95 the cache folder with the ETag.
97 # client.publish(data, tarball, [readme], cb)
99 * `data` {Object} Package data
100 * `tarball` {String | Stream} Filename or stream of the package tarball
101 * `readme` {String} Contents of the README markdown file
104 Publish a package to the registry.
106 Note that this does not create the tarball from a folder. However, it
107 can accept a gzipped tar stream or a filename to a tarball.
109 # client.star(package, starred, cb)
111 * `package` {String} Name of the package to star
112 * `starred` {Boolean} True to star the package, false to unstar it.
115 Star or unstar a package.
117 Note that the user does not have to be the package owner to star or
118 unstar a package, though other writes do require that the user be the
121 # client.tag(project, version, tag, cb)
123 * `project` {String} Project name
124 * `version` {String} Version to tag
125 * `tag` {String} Tag name to apply
128 Mark a version in the `dist-tags` hash, so that `pkg@tag`
129 will fetch the specified version.
131 # client.unpublish(name, [ver], cb)
133 * `name` {String} package name
134 * `ver` {String} version to unpublish. Leave blank to unpublish all
138 Remove a version of a package (or all versions) from the registry. When
139 the last version us unpublished, the entire document is removed from the
142 # client.upload(where, file, [etag], [nofollow], cb)
144 * `where` {String} URL path to upload to
145 * `file` {String | Stream} Either the filename or a readable stream
146 * `etag` {String} Cache ETag
147 * `nofollow` {Boolean} Do not follow 301/302 responses
150 Upload an attachment. Mostly used by `client.publish()`.