exp-response-utils
v1.0.1
Published
Utility functions for Express.js responses
Downloads
72
Readme
Express Responses Utils
This package provides utility functions for sending standardized JSON responses in an Express.js application.
Installation
npm install --save [email protected]
Available Functions
sendSuccessData(res, data, message)
sendCreatedData(res, data, message)
sendSuccess(res, message)
sendCreated(res, message)
sendUnauthorized(res, message)
sendForbidden(res, message)
sendNotFound(res, message)
sendServerError(res, error, message)
sendConflict(res, message)
SendMethodNotAllowed(res, message)
Usage Example
const express = require('express');
const app = express();
const responseUtils = require('exp-response-utils');
app.get('/api/data', (req, res) => {
const data = { key: 'value' };
responseUtils.sendSuccessData(res, data, 'Data retrieved successfully');
});
// Other usage examples of response functions
// ...
app.listen(3000, () => {
console.log('Server running on port 3000');
});
License
This package is licensed under ISC. See the LICENSE file for more details.