The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / deps / npm / node_modules / npm-registry-client / README.md @ 5aef65a9
History | View | Annotate | Download (5.1 KB)
1 |
# npm-registry-client |
---|---|
2 |
|
3 |
The code that npm uses to talk to the registry. |
4 |
|
5 |
It handles all the caching and HTTP calls. |
6 |
|
7 |
## Usage |
8 |
|
9 |
```javascript |
10 |
var RegClient = require('npm-registry-client') |
11 |
var client = new RegClient(config) |
12 |
|
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 |
18 |
}) |
19 |
``` |
20 |
|
21 |
# Configuration |
22 |
|
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 |
27 |
also be accepted. |
28 |
|
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. |
35 |
Default = `"latest"` |
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} {process.platform} {process.arch}"` |
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. |
44 |
Default=2 |
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) |
58 |
|
59 |
# client.request(method, where, [what], [etag], [nofollow], cb) |
60 |
|
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 |
67 |
* `cb` {Function} |
68 |
* `error` {Error | null} |
69 |
* `data` {Object} the parsed data object |
70 |
* `raw` {String} the json |
71 |
* `res` {Response Object} response from couch |
72 |
|
73 |
Make a request to the registry. All the other methods are wrappers |
74 |
around this. one. |
75 |
|
76 |
# client.adduser(username, password, email, cb) |
77 |
|
78 |
* `username` {String} |
79 |
* `password` {String} |
80 |
* `email` {String} |
81 |
* `cb` {Function} |
82 |
|
83 |
Add a user account to the registry, or verify the credentials. |
84 |
|
85 |
# client.get(url, [timeout], [nofollow], [staleOk], cb) |
86 |
|
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. |
93 |
|
94 |
Fetches data from the registry via a GET request, saving it in |
95 |
the cache folder with the ETag. |
96 |
|
97 |
# client.publish(data, tarball, [readme], cb) |
98 |
|
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 |
102 |
* `cb` {Function} |
103 |
|
104 |
Publish a package to the registry. |
105 |
|
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. |
108 |
|
109 |
# client.star(package, starred, cb) |
110 |
|
111 |
* `package` {String} Name of the package to star |
112 |
* `starred` {Boolean} True to star the package, false to unstar it. |
113 |
* `cb` {Function} |
114 |
|
115 |
Star or unstar a package. |
116 |
|
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 |
119 |
package owner. |
120 |
|
121 |
# client.tag(project, version, tag, cb) |
122 |
|
123 |
* `project` {String} Project name |
124 |
* `version` {String} Version to tag |
125 |
* `tag` {String} Tag name to apply |
126 |
* `cb` {Function} |
127 |
|
128 |
Mark a version in the `dist-tags` hash, so that `pkg@tag` |
129 |
will fetch the specified version. |
130 |
|
131 |
# client.unpublish(name, [ver], cb) |
132 |
|
133 |
* `name` {String} package name |
134 |
* `ver` {String} version to unpublish. Leave blank to unpublish all |
135 |
versions. |
136 |
* `cb` {Function} |
137 |
|
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 |
140 |
database. |
141 |
|
142 |
# client.upload(where, file, [etag], [nofollow], cb) |
143 |
|
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 |
148 |
* `cb` {Function} |
149 |
|
150 |
Upload an attachment. Mostly used by `client.publish()`. |