Small application/x-www-form-urlencoded request body parser
npm install urlencoded-body-parserSmall parser for http.IncomingMessage that turns application/x-www-form-urlencoded data into a javascript object using qs.
parse(req, {limit = '1mb'} = {})
- Use require('urlencoded-body-parser')
- Returns a Promise
- Buffers and parses the incoming body and returns it.
- limit is how much data is aggregated before parsing at max. It can be a Number of bytes or a string like '1mb'.
- The Promise is rejected when an error occurs
Using Micro:
``js`
const parse = require('urlencoded-body-parser')
module.exports = async function (req, res) {
const data = await parse(req)
console.log(data)
return ''
}
Using build in HTTP server:
`js
const http = require('http');
const parse = require('urlencoded-body-parser')
const server = http.createServer((req, res) => {
parse(req).then(data => {
console.log(data)
res.end();
})
});
server.listen(8000);
``