1// Express/Connect top-level generic
2// This example demonstrates adding a generic JSON and URL-encoded parser as a top-level middleware, which will parse the bodies of all incoming requests.
3// This is the simplest setup.
4
5var express = require('express')
6var bodyParser = require('body-parser')
7var app = express()
8
9// parse application/x-www-form-urlencoded
10app.use(bodyParser.urlencoded({ extended: false }))
11
12// parse application/json
13app.use(bodyParser.json())
14
15app.use(function (req, res) {
16 res.setHeader('Content-Type', 'text/plain')
17 res.write('you posted:\n')
18res.end(JSON.stringify(req.body, null, 2))})
1var bodyParser = require('body-parser')
2
3// parse application/x-www-form-urlencoded
4app.use(bodyParser.urlencoded({ extended: false }))
5
6// parse application/json
7app.use(bodyParser.json())
1import bodyParser from "body-parser";
2
3const app= express();
4app.use(bodyParser.json({ limit: "5mb", extended: true }));
5app.use(bodyParser.urlencoded({ limit: "5mb", extended: true }));
6
1var express = require('express')var bodyParser = require('body-parser') var app = express() // parse application/x-www-form-urlencodedapp.use(bodyParser.urlencoded({ extended: false })) // parse application/jsonapp.use(bodyParser.json()) app.use(function (req, res) { res.setHeader('Content-Type', 'text/plain') res.write('you posted:\n') res.end(JSON.stringify(req.body, null, 2))})