express-fail

1.0.3 • Public • Published

express-fail

Fail response for Node Express.

Installation

First install node.js and express. Then:

$ npm install express-fail

Configure Middleware

app.use(expressFail())

Setup CRSF and default status code

app.use(expressFail({
  csrf: true,
  status: 200
}))

Routing/Response

Routing:

app.post('/api/user', function (req, res) {
  if (req.body.name.trim() === '') {
    res.fail('Name is empty.')
  }
})

Response:

{
  "error": "Name is empty."
}

Package Sidebar

Install

npm i express-fail

Weekly Downloads

0

Version

1.0.3

License

ISC

Last publish

Collaborators

  • webarthur