{"_id":"@ashkiani/express-responses","name":"@ashkiani/express-responses","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ashkiani/express-responses","version":"1.0.0","description":"Reusable response helpers for Express APIs with integrated logging support — standardize your JSON/text replies and HTTP error handling with one module.","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/ashkiani/express-responses.git"},"keywords":["express","responses","http","logging","http-status","express-helper"],"author":{"name":"Siavash Ashkiani"},"license":"MIT","bugs":{"url":"https://github.com/ashkiani/express-responses/issues"},"homepage":"https://github.com/ashkiani/express-responses#readme","gitHead":"7df3be61d74587250e0a7e4cdf6089f4724267e1","_id":"@ashkiani/express-responses@1.0.0","_nodeVersion":"20.19.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-GDm2XdcOKzaRhz8kiC19YPVl68N/7gbIfiCnVyXjanqAAZzRP7nGx5cj59Bduc6l4DG5dkpJ+IJ3AtAqiGWLmQ==","shasum":"3fa326233a01b42a841a650144326d61c87180ad","tarball":"https://registry.npmjs.org/@ashkiani/express-responses/-/express-responses-1.0.0.tgz","fileCount":5,"unpackedSize":5737,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAhcuCwX7ZUW+pj4yq3oxQM1Gnbzg5OWsksYBlFGec5KAiA58lBNQFCAdJQDZ//3P3fsif00WYpF4g2AWnx1APuICw=="}]},"_npmUser":{"name":"ashkiani","email":"ashkiani@yahoo.com"},"directories":{},"maintainers":[{"name":"ashkiani","email":"ashkiani@yahoo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/express-responses_1.0.0_1747176393173_0.019678546563170807"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-13T22:46:33.057Z","1.0.0":"2025-05-13T22:46:33.382Z","modified":"2025-05-13T22:46:33.736Z"},"maintainers":[{"name":"ashkiani","email":"ashkiani@yahoo.com"}],"description":"Reusable response helpers for Express APIs with integrated logging support — standardize your JSON/text replies and HTTP error handling with one module.","homepage":"https://github.com/ashkiani/express-responses#readme","keywords":["express","responses","http","logging","http-status","express-helper"],"repository":{"type":"git","url":"git+https://github.com/ashkiani/express-responses.git"},"author":{"name":"Siavash Ashkiani"},"bugs":{"url":"https://github.com/ashkiani/express-responses/issues"},"license":"MIT","readme":"# express-responses\nReusable response helpers for Express APIs with integrated logging support — standardize your JSON/text replies and HTTP error handling with one module.\n\n---\n\n# @ashkiani/express-responses\n\nReusable HTTP response helpers for Express APIs — with optional structured logging.\n\nThis utility standardizes how your Express app sends JSON, text, and error responses. It also supports logging response details (e.g., status codes and payloads) when a log object is available.\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @ashkiani/express-responses\n```\n\n---\n\n## 🛠 Usage\n\n1. Import the module:\n\n```js\nconst resUtils = require('@ashkiani/express-responses');\n```\n\n2. Use it in your route handlers:\n\n```js\napp.get(\"/api/example\", async (req, res) => {\n    const logEntry = {\n        requestId: \"abc123\",\n        timestamp: new Date()\n    };\n\n    try {\n        await resUtils.sendJsonResponse(res, 200, { message: \"Success!\" }, logEntry);\n    } catch (err) {\n        await resUtils.send500InternalError(res, logEntry);\n    }\n\n    // Optional: Save logEntry to DB\n});\n```\n\n---\n\n## 📘 API Reference\n\n### `sendTextResponse(res, statusCode, message, logEntry?)`\n\nSends plain text and, if a `logEntry` object is provided, logs the response.\n\n### `sendJsonResponse(res, statusCode, jsonObj, logEntry?)`\n\nSends JSON and logs it if a `logEntry` object is present.\n\n### `send204NoContent(res, logEntry?)`\n\nSends a 204 No Content response.\n\n---\n\n### Predefined Error Responses\n\nThese are convenience wrappers for common error statuses:\n\n| Function                      | Description                 |\n| ----------------------------- | --------------------------- |\n| `send400BadReq()`             | Bad Request (400)           |\n| `send401UnAuth()`             | Unauthorized (401)          |\n| `send500InternalError()`      | Internal Server Error (500) |\n| `send503ServiceUnavailable()` | Service Unavailable (503)   |\n\nEach function accepts `(res, logEntry?)` and safely logs the response if `logEntry` is provided.\n\n---\n\n## 💡 Notes\n\n* Logging is **optional**. If `logEntry` is omitted, the function still works without throwing errors.\n* These helpers work well with any logging system — just ensure your `logEntry` object includes a `response` field if you want to store response details.\n* Compatible with [@ashkiani/mongo-logger](https://www.npmjs.com/package/@ashkiani/mongo-logger) for full request-response auditing.\n\n---\n\n## 📄 License\n\nMIT © Siavash Ashkiani\n\n---","readmeFilename":"README.md","_rev":"1-a96d95955f86d9a7735a0df9e7610254"}