{"library":"request-spy","title":"request-spy","description":"request-spy is a Node.js utility designed to intercept and report on all outgoing HTTP/HTTPS requests made within a Node.js application. It operates by patching Node.js's internal request mechanisms, allowing users to log errors, monitor hostnames, paths, methods, HTTP status codes, and the request duration. The package is currently at version 0.0.10. Given its last known update around 2017 (indicated by the README copyright), it appears to be either in a long-term maintenance state or, more likely, abandoned, suggesting an infrequent or non-existent release cadence. Its primary differentiator is its simple, global interception mechanism, which can be useful for debugging or basic metrics collection without modifying individual request calls. However, its age may present significant compatibility challenges with newer Node.js runtime versions, especially concerning modern module systems like ESM or the `fetch` API.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install request-spy"],"cli":null},"imports":["const requestSpy = require('request-spy');","const requestSpy = require('request-spy');\nrequestSpy.spy((error, requestData) => { /* ... */ });","const requestSpy = require('request-spy');\nrequestSpy.restore();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const requestSpy = require('request-spy');\nconst http = require('http'); // For making a sample outgoing request\n\nconsole.log('Starting request-spy example...');\n\n// Spy on all outgoing requests\nrequestSpy.spy((error, requestData) => {\n  if (error) {\n    console.error('⚠️ Socket error during outgoing request:', error.message);\n  } else {\n    console.log('✨ Outgoing Request Spied:');\n    console.log(`  Hostname: ${requestData.hostname}`);\n    console.log(`  Path: ${requestData.path}`);\n    console.log(`  Method: ${requestData.method}`);\n    if (requestData.statusCode) {\n      console.log(`  Status Code: ${requestData.statusCode}`);\n    }\n    console.log(`  Request Time: ${requestData.requestTime}ms`);\n  }\n});\n\n// Make a sample outgoing request to trigger the spy\nconst options = {\n  hostname: 'jsonplaceholder.typicode.com',\n  port: 80,\n  path: '/todos/1',\n  method: 'GET',\n};\n\nconst req = http.request(options, (res) => {\n  console.log(`Response status from external API: ${res.statusCode}`);\n  res.on('data', () => {}); // Consume response data to ensure 'end' event fires\n  res.on('end', () => {\n    console.log('Request to jsonplaceholder.typicode.com completed.');\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(`Problem with the sample request: ${e.message}`);\n});\n\nreq.end();\n\n// Restore the original http/https modules after a short delay\nsetTimeout(() => {\n  requestSpy.restore();\n  console.log('request-spy restored. No more requests will be spied upon.');\n}, 2000);\n","lang":"javascript","description":"This quickstart demonstrates how to initialize `request-spy` to intercept all outgoing HTTP requests, log their details, and then restore the original Node.js behavior after a short period. It includes an example HTTP request to an external API to trigger the spy.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}