1.1.0 • Published 8 years ago

raw-text v1.1.0

Weekly downloads
13
License
MIT
Repository
github
Last release
8 years ago

Raw Text

Parse raw request body as text

Installation

npm install --save raw-text

Usage

Using Micro

const parse = require('raw-text')

module.exports = async function (req, res) {
  const text = await parse(req)
  console.log(text)

  return ''
}

Using the built in HTTP server provided by node.js

const http = require('http');
const parse = require('raw-text')

const server = http.createServer((req, res) => {
  const text = parse(req).then(text => {
    console.log(text)
    res.end()
  })
})

server.listen(8000)

Api

parse(req, {limit = '1mb'})

  • Use require('raw-text')
  • Returns a Promise (can be used with async/await)
  • Buffers the incoming body, calls toString() 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, it is your responsibility to catch it.

Background

Requested feature for Micro in pull request 116 and 118.

Credits to

Jeremy Morrell and Sam Garson for explaining the need for this package.

1.1.0

8 years ago

1.0.0

8 years ago