npm install raw-textParse raw request body as text
npm install --save raw-text
Using Micro
``js
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
`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)
`
parse(req, {limit = '1mb'})
- Use require('raw-text')Promise
- Returns a (can be used with async/await)toString()
- Buffers the incoming body, calls and returns it.Number
- limit is how much data is aggregated before parsing at max. It can be a of bytes or a string like '1mb'.Promise` is rejected when an error occurs, it is your responsibility to catch it.
- The
#### 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.