{"library":"npm-request","title":"npm-request","description":"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.","language":"javascript","status":"abandoned","last_verified":"Wed Apr 22","install":{"commands":["npm install npm-request"],"cli":null},"imports":["const npmRequest = require('npm-request');","npmRequest(options, callback);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const npmRequest = require('npm-request');\nconst fs = require('fs');\nconst path = require('path');\n\n// Emulate .npmrc content for demonstration. \n// In a real scenario, this would be read from your actual ~/.npmrc or project-level .npmrc.\n// For a private registry, ensure your .npmrc has an auth token, e.g., \n// `//registry.example.com/:_authToken=\"YOUR_NPM_TOKEN\"`\n// Or for basic auth: `//registry.example.com/:_auth=BASE64_USERNAME_PASSWORD`\nconst registryUrl = process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org/';\nconst packageName = 'some-private-package'; // Replace with a real package you have access to\n\nconst options = {\n  url: `${registryUrl}${packageName}`,\n  json: true, // Expect JSON response\n  // npm-request automatically reads .npmrc for auth, no manual headers needed for basic cases\n  // However, you might need to specify strictSSL for private registries if not globally configured\n  // strictSSL: false, // Use with caution in development for self-signed certs\n};\n\nconsole.log(`Attempting to fetch ${packageName} from ${registryUrl} with npmrc auth...\\n`);\n\nnpmRequest(options, (error, response, body) => {\n  if (error) {\n    console.error('Request failed:', error.message);\n    console.error('Stack:', error.stack);\n    return;\n  }\n\n  if (response.statusCode === 200) {\n    console.log(`Successfully fetched metadata for ${packageName}.`);\n    console.log('Partial response body (first 200 chars):', JSON.stringify(body, null, 2).substring(0, 200), '...');\n  } else if (response.statusCode === 401 || response.statusCode === 403) {\n    console.error(`Authentication failed for ${packageName}. Status: ${response.statusCode}`);\n    console.error('Please ensure your .npmrc has valid authentication for', registryUrl);\n    console.error('Response headers:', response.headers);\n  } else if (response.statusCode === 404) {\n    console.error(`Package '${packageName}' not found on ${registryUrl}. Status: ${response.statusCode}`);\n  } else {\n    console.error(`Unexpected status code: ${response.statusCode}`);\n    console.error('Response body:', body);\n  }\n});\n\n// Example of how npm login typically updates .npmrc for a private registry:\n// `npm config set registry https://my-private-registry.com/`\n// `npm login --registry https://my-private-registry.com/`\n// This will typically add an entry like `//my-private-registry.com/:_authToken=\"your-token\"`\n","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}