Simple helper module for express
yarn
yarn add express-easy-helper
npm
npm install express-easy-helper --save
import { success, unauthorized, forbidden, error } from "express-easy-helper";
import express from "express";
const app = express();
// success
app.get("/", (req, res) => {
success(res, { hello: "world" });
});
// unauthorized
app.get("/unauthorized", (req, res) => {
unauthorized(res);
});
// forbidden
app.get("/protected", (req, res) => {
forbidden(res);
});
// error
app.get("/error", (req, res) => {
error(res);
});
// 200
success(res);
// 400
badRequest(res);
// 401
unauthorized(res);
// 403
forbidden(res);
// 404
notFound(res);
//405
unsupportedAction(res);
//422
invalid(res);
// 500
error(res);
// Basic
success(res);
// Code status
success(res, 201);
// Data
success(res, { hello: "world" });
// Code status and data
success(res, 201, { hello: "world" });
MIT © Leonardo Rico