node-req is a minimalist I/O module designed to parse and extract specific values from Node.js's native `http.IncomingMessage` object, explicitly designed with no side-effects. It provides a set of helper methods for accessing common request components such as query strings, HTTP method, headers, IP addresses, protocol (HTTP/HTTPS), subdomains, and content negotiation details. Currently at version 2.1.2, this package has not received updates in approximately six years, indicating it is no longer actively maintained. Its core differentiation lies in its pure parsing approach, making no assumptions about routing or higher-level HTTP handling, thus allowing it to integrate into various Node.js server architectures as a low-level utility. It leverages the `qs` package internally for robust query string parsing.
npm install node-reqVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic Node.js HTTP server and use `node-req` to parse various components of an incoming request, including query parameters, HTTP method, headers, and client IP, then respond with the extracted information.
Consider migrating to actively maintained alternatives for HTTP request parsing or ensuring thorough security audits if continuing to use this library. For HTTP client functionality, use `undici`, `axios`, or native `fetch`.
Ensure your project or the specific file using `node-req` is configured for CommonJS, or use dynamic `import()` if absolutely necessary within an ESM context, though this is generally not recommended for core dependencies.
For new projects, prefer modern, actively maintained libraries for HTTP request parsing. For existing projects, evaluate the risk of using an unmaintained dependency and consider gradual migration.
Ensure you are using `const nodeReq = require('node-req')` for importing in a CommonJS context. If in an ESM project, consider using `import * as nodeReq from 'node-req'` or migrating to an ESM-compatible alternative.Either convert the consuming file back to CommonJS (by ensuring it does not use `import`/`export` and removing `"type": "module"` from its nearest `package.json`), or use a dynamic import (`const nodeReq = await import('node-req')`) within the ESM file, then access its properties (`nodeReq.default.get(req)`). The best long-term fix is to migrate to an actively maintained ESM-compatible library.