Registry / http-networking / node-res

node-res

JSON →
library5.0.1jsnpmunverified

node-res is a lightweight Node.js module designed to simplify the creation of HTTP responses by providing a facade over the native `http.ServerResponse` object. It offers utility methods to easily set common HTTP headers, define response statuses, and automatically determine appropriate `Content-Type` headers based on the body content. As of its latest stable version `5.0.1`, published over seven years ago in August 2018, the library appears to be in a maintenance-only state with no active development or regular release cadence. Its key differentiator is its minimal footprint and focus on direct manipulation of the response object without introducing significant abstraction layers, offering helpers for common tasks like sending HTML, JSON, or JSONP, and handling ETags. It is primarily built for CommonJS environments.

http-networkingweb-framework
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

The library primarily exports a single object for CommonJS. While some transpilers might handle `import nodeRes from 'node-res'`, it's not a native ESM export.

const nodeRes = require('node-res')

Methods like `send` are properties of the default exported `nodeRes` object, not named exports.

nodeRes.send(req, res, body, statusCode)

Similar to `send`, `jsonp` is a method accessed via the `nodeRes` object.

nodeRes.jsonp(req, res, data, callbackFn)

Demonstrates how to set up a basic Node.js HTTP server and use `node-res` to send different types of responses (HTML, JSON, custom status messages, and JSONP) with automatic content-type handling.

const http = require('http'); const nodeRes = require('node-res'); const server = http.createServer((req, res) => { if (req.url === '/') { // Send a simple HTML response with status 200 nodeRes.send(req, res, '<h1>Hello from node-res!</h1>'); } else if (req.url === '/json') { // Send a JSON response with status 200 nodeRes.send(req, res, { message: 'This is a JSON response', timestamp: Date.now() }); } else if (req.url === '/error') { // Send a custom status (500) and message nodeRes.send(req, res, 'Something went wrong!', 500); } else if (req.url.startsWith('/jsonp')) { // Send a JSONP response, expecting '?callback=myCallback' query parameter const callbackFn = new URLSearchParams(req.url.split('?')[1]).get('callback') || 'callback'; nodeRes.jsonp(req, res, { data: 'JSONP data from node-res' }, callbackFn); } else { // 404 Not Found response nodeRes.send(req, res, 'Not Found', 404); } }); const PORT = process.env.PORT || 3000; server.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); console.log('Try visiting:'); console.log(`- http://localhost:${PORT}/`); console.log(`- http://localhost:${PORT}/json`); console.log(`- http://localhost:${PORT}/error`); console.log(`- http://localhost:${PORT}/jsonp?callback=myCallbackFunction`); });
Debug
Known footguns
gotchaThe `node-res` package has not been updated since August 2018. This means it may not actively address new security vulnerabilities, performance optimizations, or compatibility issues with very recent Node.js runtime versions or web standards.
gotcha`node-res` is designed for CommonJS (CJS) environments using `require()`. While some tools might transpile it, direct `import` statements in native ES Modules (ESM) projects might lead to unexpected behavior or require specific build configurations.
gotchaThe library directly manipulates the native `http.ServerResponse` object. While this offers low-level control, it might not integrate seamlessly with higher-level web frameworks (like Express.js, Koa, Hapi) that often wrap or extend the native response object with their own abstractions and middleware chains.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources