urlencoded-body-parser
v3.0.0
Published
Small application/x-www-form-urlencoded request body parser
Downloads
37,730
Readme
Urlencoded Body Parser
Small parser for http.IncomingMessage that turns application/x-www-form-urlencoded
data into a javascript object using qs.
Api
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 aNumber
of bytes or a string like'1mb'
.- The Promise is rejected when an error occurs
Usage
Using Micro:
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:
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);