Express.js response formatting middleware
$ npm install api-response-middleware
var responseMiddleware = require('api-response-middleware');
app.use(responseMiddleware(options)); //App is an Express.js app. Pass in options
The function takes an option options object that may contain any of the following keys:
failCodes
An array of HTTP status codes that should be treated as 'fail', instead of 'error' (more on this below)
This middleware attaches a few new methods to the Express 'res' object. These methods will send a response in one of three formats - Success, Fail, or Error
{
"status":"success",
"payload":{}
}
{
"status":"fail",
"message":"Oops!"
}
{
"status":"error",
"message":"Oops!"
}