express-easy-helper
v2.5.1
Published
Simple helper module for express
Downloads
118
Maintainers
Readme
express-easy-helper
Simple helper module for express
Installation
yarn
yarn add express-easy-helper
npm
npm install express-easy-helper --save
Usage
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);
});
Method's
// 200
success(res);
// 400
badRequest(res);
// 401
unauthorized(res);
// 403
forbidden(res);
// 404
notFound(res);
//405
unsupportedAction(res);
//422
invalid(res);
// 500
error(res);
Options
// Basic
success(res);
// Code status
success(res, 201);
// Data
success(res, { hello: "world" });
// Code status and data
success(res, 201, { hello: "world" });
License
MIT © Leonardo Rico