What is npm-registry-client?
The npm-registry-client package is a client for interacting with the npm registry. It allows you to perform various operations such as fetching package metadata, publishing packages, and managing package versions.
What are npm-registry-client's main functionalities?
Fetching Package Metadata
This feature allows you to fetch metadata for a specific package from the npm registry. The code sample demonstrates how to fetch metadata for the 'npm' package.
const NpmRegistryClient = require('npm-registry-client');
const client = new NpmRegistryClient();
const uri = 'https://registry.npmjs.org/npm';
client.get(uri, {}, (error, data, raw, res) => {
if (error) {
console.error(error);
} else {
console.log(data);
}
});
Publishing a Package
This feature allows you to publish a package to the npm registry. The code sample demonstrates how to publish a package named 'my-package' with version '1.0.0'.
const NpmRegistryClient = require('npm-registry-client');
const client = new NpmRegistryClient();
const uri = 'https://registry.npmjs.org/npm';
const params = { metadata: { name: 'my-package', version: '1.0.0' }, access: 'public' };
client.publish(uri, params, (error, data) => {
if (error) {
console.error(error);
} else {
console.log('Package published successfully');
}
});
Managing Package Versions
This feature allows you to manage and list the available versions of a package. The code sample demonstrates how to list all available versions of the 'npm' package.
const NpmRegistryClient = require('npm-registry-client');
const client = new NpmRegistryClient();
const uri = 'https://registry.npmjs.org/npm';
client.get(uri, {}, (error, data) => {
if (error) {
console.error(error);
} else {
console.log('Available versions:', Object.keys(data.versions));
}
});
Other packages similar to npm-registry-client
npm
The 'npm' package itself provides a command-line interface for interacting with the npm registry. It offers a wide range of functionalities including installing packages, publishing packages, and managing dependencies. Compared to npm-registry-client, it is more comprehensive and user-friendly for general use.
yarn
Yarn is a package manager that also interacts with the npm registry. It offers similar functionalities such as installing, publishing, and managing packages. Yarn is known for its speed and reliability, and it provides a different workflow compared to npm-registry-client.
pnpm
pnpm is another package manager that interacts with the npm registry. It is designed to be fast and efficient, with a unique approach to managing node_modules. Compared to npm-registry-client, pnpm focuses on performance and disk space optimization.
npm-registry-client
The code that npm uses to talk to the registry.
It handles all the caching and HTTP calls.
Usage
var RegClient = require('npm-registry-client')
var client = new RegClient(config)
var uri = "npm://registry.npmjs.org/npm"
var options = {timeout: 1000}
client.get(uri, options, function (error, data, raw, res) {
})
Registry URLs
The registry calls take either a full URL pointing to a resource in the
registry, or a base URL for the registry as a whole (for the base URL, any path
will be ignored). In addition to http
and https
, npm
URLs are allowed.
npm
URLs are https
URLs with the additional restrictions that they will
always include authorization credentials, and the response is always registry
metadata (and not tarballs or other attachments).
Configuration
This program is designed to work with
npmconf, but you can also pass in
a plain-jane object with the appropriate configs, and it'll shim it
for you. Any configuration thingie that has get/set/del methods will
also be accepted.
cache
Required {String} Path to the cache folderalways-auth
{Boolean} Auth even for GET requests.auth
{String} A base64-encoded username:password
email
{String} User's email addresstag
{String} The default tag to use when publishing new packages.
Default = "latest"
ca
{String} Cerficate signing authority certificates to trust.cert
{String} Client certificate (PEM encoded). Enable access
to servers that require client certificateskey
{String} Private key (PEM encoded) for client certificate 'cert'strict-ssl
{Boolean} Whether or not to be strict with SSL
certificates. Default = true
user-agent
{String} User agent header to send. Default =
"node/{process.version} {process.platform} {process.arch}"
log
{Object} The logger to use. Defaults to require("npmlog")
if
that works, otherwise logs are disabled.fetch-retries
{Number} Number of times to retry on GET failures.
Default=2fetch-retry-factor
{Number} factor
setting for node-retry
. Default=10fetch-retry-mintimeout
{Number} minTimeout
setting for node-retry
.
Default=10000 (10 seconds)fetch-retry-maxtimeout
{Number} maxTimeout
setting for node-retry
.
Default=60000 (60 seconds)proxy
{URL} The url to proxy requests through.https-proxy
{URL} The url to proxy https requests through.
Defaults to be the same as proxy
if unset._auth
{String} The base64-encoded authorization header.username
_password
{String} Username/password to use to generate
_auth
if not supplied._token
{Object} A token for use with
couch-login
client.request(method, uri, options, cb)
method
{String} HTTP methoduri
{String} URI pointing to the resource to requestoptions
{Object} Object containing optional per-request properties.
what
{Stream | Buffer | String | Object} The request body. Objects
that are not Buffers or Streams are encoded as JSON.etag
{String} The cached ETagfollow
{Boolean} Follow 302/301 responses (defaults to true)
cb
{Function}
error
{Error | null}data
{Object} the parsed data objectraw
{String} the jsonres
{Response Object} response from couch
Make a request to the registry. All the other methods are wrappers around
request
.
client.adduser(base, username, password, email, cb)
base
{String} Base registry URLusername
{String}password
{String}email
{String}cb
{Function}
Add a user account to the registry, or verify the credentials.
client.deprecate(uri, version, message, cb)
uri
{String} Full registry URI for the deprecated packageversion
{String} Semver version rangemessage
{String} The message to use as a deprecation warningcb
{Function}
Deprecate a version of a package in the registry.
client.bugs(uri, cb)
uri
{String} Full registry URI for the packagecb
{Function}
Get the url for bugs of a package
client.get(uri, options, cb)
uri
{String} The complete registry URI to fetchoptions
{Object} Object containing optional per-request properties.
timeout
{Number} Duration before the request times out.follow
{Boolean} Follow 302/301 responses (defaults to true)staleOk
{Boolean} If there's cached data available, then return that
to the callback quickly, and update the cache the background.
Fetches data from the registry via a GET request, saving it in the cache folder
with the ETag.
client.publish(uri, data, tarball, cb)
uri
{String} The registry URI to publish todata
{Object} Package datatarball
{String | Stream} Filename or stream of the package tarballcb
{Function}
Publish a package to the registry.
Note that this does not create the tarball from a folder. However, it can
accept a gzipped tar stream or a filename to a tarball.
client.star(uri, starred, cb)
uri
{String} The complete registry URI to starstarred
{Boolean} True to star the package, false to unstar it.cb
{Function}
Star or unstar a package.
Note that the user does not have to be the package owner to star or unstar a
package, though other writes do require that the user be the package owner.
client.stars(base, username, cb)
base
{String} The base URL for the registryusername
{String} Name of user to fetch starred packages for.cb
{Function}
View your own or another user's starred packages.
client.tag(uri, version, tag, cb)
uri
{String} The complete registry URI to tagversion
{String} Version to tagtag
{String} Tag name to applycb
{Function}
Mark a version in the dist-tags
hash, so that pkg@tag
will fetch the
specified version.
client.unpublish(uri, [ver], cb)
uri
{String} The complete registry URI to unpublishver
{String} version to unpublish. Leave blank to unpublish all
versions.cb
{Function}
Remove a version of a package (or all versions) from the registry. When the
last version us unpublished, the entire document is removed from the database.
client.upload(uri, file, [etag], [nofollow], cb)
uri
{String} The complete registry URI to upload tofile
{String | Stream} Either the filename or a readable streametag
{String} Cache ETagnofollow
{Boolean} Do not follow 301/302 responsescb
{Function}
Upload an attachment. Mostly used by client.publish()
.