Tiniest body parser in the universe. Built for modern Node.js.
Check out deno-libs/parsec for Deno port.
- π JSON / raw / urlencoded / multipart support
- π¦ tiny package size (8KB dist size)
- π₯ no dependencies
- β¨ tinyhttp and Express support
- β‘ 40% faster than body-parser and 20x faster than formidable
# pnpm
pnpm i milliparsec
# bun
bun i milliparsec
Use a middleware inside a server:
import { createServer } from 'node:http'
import { json } from 'milliparsec'
const server = createServer(async (req: ReqWithBody, res) => {
await json()(req, res, (err) => void err && res.end(err))
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(req.body))
})
The parsec is a unit of length used to measure large distances to astronomical objects outside the Solar System.