urlencoded-body-parser

3.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i urlencoded-body-parser

Weekly Downloads

20,506

Version

3.0.0

License

MIT

Unpacked Size

2.21 kB

Total Files

3

Last publish

Collaborators

  • timneutkens