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(options)
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 * `registry` **Required** {String} URL to the registry
24 * `cache` **Required** {String} Path to the cache folder
25 * `alwaysAuth` {Boolean} Auth even for GET requests.
26 * `auth` {String} A base64-encoded `username:password`
27 * `email` {String} User's email address
28 * `tag` {String} The default tag to use when publishing new packages.
30 * `ca` {String} Cerficate signing authority certificates to trust.
31 * `strictSSL` {Boolean} Whether or not to be strict with SSL
32 certificates. Default = `true`
33 * `userAgent` {String} User agent header to send. Default =
34 `"node/{process.version}"`
35 * `log` {Object} The logger to use. Defaults to `require("npmlog")` if
36 that works, otherwise logs are disabled.
37 * `retries` {Number} Number of times to retry on GET failures.
39 * `retryFactor` {Number} `factor` setting for `node-retry`. Default=10
40 * `retryMinTimeout` {Number} `minTimeout` setting for `node-retry`.
41 Default=10000 (10 seconds)
42 * `retryMaxTimeout` {Number} `maxTimeout` setting for `node-retry`.
43 Default=60000 (60 seconds)
45 # client.request(method, where, [what], [etag], [nofollow], cb)
47 * `method` {String} HTTP method
48 * `where` {String} Path to request on the server
49 * `what` {Stream | Buffer | String | Object} The request body. Objects
50 that are not Buffers or Streams are encoded as JSON.
51 * `etag` {String} The cached ETag
52 * `nofollow` {Boolean} Prevent following 302/301 responses
54 * `error` {Error | null}
55 * `data` {Object} the parsed data object
56 * `raw` {String} the json
57 * `res` {Response Object} response from couch
59 Make a request to the registry. All the other methods are wrappers
62 # client.adduser(username, password, email, cb)
69 Add a user account to the registry, or verify the credentials.
71 # client.get(url, [timeout], [nofollow], [staleOk], cb)
73 * `url` {String} The url path to fetch
74 * `timeout` {Number} Number of seconds old that a cached copy must be
75 before a new request will be made.
76 * `nofollow` {Boolean} Do not follow 301/302 responses
77 * `staleOk` {Boolean} If there's cached data available, then return that
78 to the callback quickly, and update the cache the background.
80 Fetches data from the registry via a GET request, saving it in
81 the cache folder with the ETag.
83 # client.publish(data, tarball, [readme], cb)
85 * `data` {Object} Package data
86 * `tarball` {String | Stream} Filename or stream of the package tarball
87 * `readme` {String} Contents of the README markdown file
90 Publish a package to the registry.
92 Note that this does not create the tarball from a folder. However, it
93 can accept a gzipped tar stream or a filename to a tarball.
95 # client.star(package, starred, cb)
97 * `package` {String} Name of the package to star
98 * `starred` {Boolean} True to star the package, false to unstar it.
101 Star or unstar a package.
103 Note that the user does not have to be the package owner to star or
104 unstar a package, though other writes do require that the user be the
107 # client.tag(project, version, tag, cb)
109 * `project` {String} Project name
110 * `version` {String} Version to tag
111 * `tag` {String} Tag name to apply
114 Mark a version in the `dist-tags` hash, so that `pkg@tag`
115 will fetch the specified version.
117 # client.unpublish(name, [ver], cb)
119 * `name` {String} package name
120 * `ver` {String} version to unpublish. Leave blank to unpublish all
124 Remove a version of a package (or all versions) from the registry. When
125 the last version us unpublished, the entire document is removed from the
128 # client.upload(where, file, [etag], [nofollow], cb)
130 * `where` {String} URL path to upload to
131 * `file` {String | Stream} Either the filename or a readable stream
132 * `etag` {String} Cache ETag
133 * `nofollow` {Boolean} Do not follow 301/302 responses
136 Upload an attachment. Mostly used by `client.publish()`.