Skip to content

Commit aa35250

Browse files
authored
Create README.md
1 parent 5bf308c commit aa35250

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
11
# bodyparser-json-error
22
Beautify body parser JSON syntax error
3+
4+
## Installation
5+
6+
```
7+
npm install bodyparser-json-error --save
8+
```
9+
10+
## Usage
11+
12+
```javascript
13+
14+
var express = require('express');
15+
var bodyParser = require('body-parser');
16+
var bodyParserError = require('bodyparser-json-error');
17+
18+
var app = express();
19+
20+
app.use(bodyParser.urlencoded({
21+
extended: true
22+
}));
23+
app.use(bodyParser.json());
24+
25+
// Beautify body parser json syntax error
26+
app.use(bodyParserError.beautify());
27+
28+
```
29+
30+
## Middleware Options
31+
You can optionally set the status code and response for the body parser syntax error.
32+
33+
```javascript
34+
app.use(bodyParserError.beautify({status: 500 , res: {msg: 'You sent a bad JSON !'}}));
35+
```
36+
37+
The output:
38+
39+
**HTTP Status Code:** 400
40+
41+
```javascript
42+
{
43+
 "msg": "You sent a bad JSON !"
44+
}
45+
```
46+
47+
### Options
48+
* status: The response status code. **Default:** 400
49+
* res: The response body. **Default:** ``{msg: 'Invalid JSON'}``
50+
51+
## License
52+
MIT License

0 commit comments

Comments
 (0)