3.0.0 • Published 5 years ago

urlencoded-body-parser v3.0.0

Weekly downloads
3,543
License
MIT
Repository
github
Last release
5 years ago

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 a Number 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);