Registry / http-networking / npm-request

npm-request

JSON →
library1.0.0jsnpmunverified

npm-request is a utility library (current stable version 1.0.0) designed to facilitate authenticated HTTP requests by automatically utilizing credentials found in a user's `.npmrc` file. This package wraps the functionality of the widely used, but now deprecated, `request` library to handle the actual network communication. Its primary differentiator is the seamless integration with npm's authentication mechanism, simplifying access to private registries or authenticated npm endpoints. However, it has not seen updates since March 2016, and its core dependency, the `request` library, was officially deprecated in February 2020 and is no longer actively maintained. Consequently, `npm-request` is considered an abandoned project, lacking modern features, security patches, or compatibility with contemporary JavaScript practices, and should not be used for new development. Its release cadence was effectively halted years ago with its last update.

npm install npm-request
INSTALL
IMPORT
SIG · NPM-REQUEST
N
npm-request
http-networkingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

npmRequest
const npmRequest = require('npm-request');
import npmRequest from 'npm-request';
This package primarily uses CommonJS `require` syntax as it was last updated in 2016, predating widespread ESM adoption in Node.js.
requestOptions
npmRequest(options, callback);
npmRequest.get(options, callback);
The API is callback-based, mirroring the underlying 'request' library. Direct promise-based usage is not supported without promisification.

Demonstrates making an authenticated GET request to an npm registry endpoint using credentials automatically sourced from the user's `.npmrc` file, and handling various response scenarios.

const npmRequest = require('npm-request'); const fs = require('fs'); const path = require('path'); // Emulate .npmrc content for demonstration. // In a real scenario, this would be read from your actual ~/.npmrc or project-level .npmrc. // For a private registry, ensure your .npmrc has an auth token, e.g., // `//registry.example.com/:_authToken="YOUR_NPM_TOKEN"` // Or for basic auth: `//registry.example.com/:_auth=BASE64_USERNAME_PASSWORD` const registryUrl = process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org/'; const packageName = 'some-private-package'; // Replace with a real package you have access to const options = { url: `${registryUrl}${packageName}`, json: true, // Expect JSON response // npm-request automatically reads .npmrc for auth, no manual headers needed for basic cases // However, you might need to specify strictSSL for private registries if not globally configured // strictSSL: false, // Use with caution in development for self-signed certs }; console.log(`Attempting to fetch ${packageName} from ${registryUrl} with npmrc auth...\n`); npmRequest(options, (error, response, body) => { if (error) { console.error('Request failed:', error.message); console.error('Stack:', error.stack); return; } if (response.statusCode === 200) { console.log(`Successfully fetched metadata for ${packageName}.`); console.log('Partial response body (first 200 chars):', JSON.stringify(body, null, 2).substring(0, 200), '...'); } else if (response.statusCode === 401 || response.statusCode === 403) { console.error(`Authentication failed for ${packageName}. Status: ${response.statusCode}`); console.error('Please ensure your .npmrc has valid authentication for', registryUrl); console.error('Response headers:', response.headers); } else if (response.statusCode === 404) { console.error(`Package '${packageName}' not found on ${registryUrl}. Status: ${response.statusCode}`); } else { console.error(`Unexpected status code: ${response.statusCode}`); console.error('Response body:', body); } }); // Example of how npm login typically updates .npmrc for a private registry: // `npm config set registry https://my-private-registry.com/` // `npm login --registry https://my-private-registry.com/` // This will typically add an entry like `//my-private-registry.com/:_authToken="your-token"`
Debug
Known issues
breakingThe underlying 'request' library, which 'npm-request' depends on, was deprecated on Feb 11, 2020, and is no longer maintained. This means 'npm-request' also effectively ceased maintenance at that time and will not receive updates or security fixes.
fix
Migrate to modern HTTP clients like `node-fetch`, `axios`, or Node.js's built-in `http`/`https` modules, and manually handle `.npmrc` parsing for authentication if needed, or use libraries designed for npm registry interaction.
affects: >=1.0.0
gotchaUsing 'npm-request' in new projects is highly discouraged due to its abandoned status and reliance on a deprecated, potentially insecure dependency. Continued use may introduce security vulnerabilities and compatibility issues with newer Node.js versions.
fix
Refactor existing code to use actively maintained HTTP clients. For npm-specific authentication, consider dedicated registry clients or manual parsing of `.npmrc` with a robust HTTP client.
affects: >=1.0.0
gotchaThe package primarily uses callback-based APIs, which can be cumbersome in modern asynchronous JavaScript codebases. It does not natively support Promises or async/await syntax.
fix
Wrap `npmRequest` calls in a Promise constructor or use `util.promisify` (Node.js 8+) for better integration with modern async patterns, though full migration away is recommended. Example: `const promisifiedNpmRequest = util.promisify(npmRequest);`
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'request'
The underlying 'request' package is not installed or resolved correctly, possibly due to `npm-request`'s outdated dependency declaration or issues with `npm install`.
fix
Ensure `request` is listed as a direct dependency or manually install it: `npm install request`.
TypeError: npmRequest is not a function
Attempting to use `npm-request` with ES module `import` syntax or an incorrect CommonJS `require` call, or expecting a different export structure.
fix
Use the correct CommonJS `require` syntax: `const npmRequest = require('npm-request');` Ensure you are calling the main exported function or object correctly, typically `npmRequest(options, callback)`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
requestrequiredCore dependency for making HTTP requests. The 'request' package is deprecated and unmaintained, making this package also effectively abandoned and insecure.
Agent activity
8 hits · last 30 days
node
8
Resources
npm-request — npm install npm-request · libregistry