{"library":"node-res","title":"Node.js HTTP Response Builder","description":"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.","language":"javascript","status":"maintenance","last_verified":"Tue Apr 21","install":{"commands":["npm install node-res"],"cli":null},"imports":["const nodeRes = require('node-res')","nodeRes.send(req, res, body, statusCode)","nodeRes.jsonp(req, res, data, callbackFn)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const http = require('http');\nconst nodeRes = require('node-res');\n\nconst server = http.createServer((req, res) => {\n  if (req.url === '/') {\n    // Send a simple HTML response with status 200\n    nodeRes.send(req, res, '<h1>Hello from node-res!</h1>');\n  } else if (req.url === '/json') {\n    // Send a JSON response with status 200\n    nodeRes.send(req, res, { message: 'This is a JSON response', timestamp: Date.now() });\n  } else if (req.url === '/error') {\n    // Send a custom status (500) and message\n    nodeRes.send(req, res, 'Something went wrong!', 500);\n  } else if (req.url.startsWith('/jsonp')) {\n    // Send a JSONP response, expecting '?callback=myCallback' query parameter\n    const callbackFn = new URLSearchParams(req.url.split('?')[1]).get('callback') || 'callback';\n    nodeRes.jsonp(req, res, { data: 'JSONP data from node-res' }, callbackFn);\n  } else {\n    // 404 Not Found response\n    nodeRes.send(req, res, 'Not Found', 404);\n  }\n});\n\nconst PORT = process.env.PORT || 3000;\nserver.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log('Try visiting:');\n  console.log(`- http://localhost:${PORT}/`);\n  console.log(`- http://localhost:${PORT}/json`);\n  console.log(`- http://localhost:${PORT}/error`);\n  console.log(`- http://localhost:${PORT}/jsonp?callback=myCallbackFunction`);\n});","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}