{"library":"milliparsec","title":"Milliparsec: Tiny HTTP Body Parser","description":"Milliparsec is a minimalistic and performant HTTP body parser for modern Node.js environments, currently at version 5.1.1. It provides middleware for parsing JSON, raw, URL-encoded, and multipart form data, making it compatible with frameworks like tinyhttp and Express. The library boasts a tiny package size (under 8KB) and zero dependencies, setting it apart from more heavy-weight alternatives like `body-parser` and `formidable`, offering significantly faster parsing speeds (approximately 15% faster than `body-parser` and 4x faster than `formidable`). It receives active development, with several minor and patch releases in quick succession, indicating a steady release cadence for bug fixes and feature enhancements, such as the recently added `type` and `reviver` options for JSON parsing in v5.1.0.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install milliparsec"],"cli":null},"imports":["import { json } from 'milliparsec'","import { urlencoded } from 'milliparsec'","import { raw } from 'milliparsec'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createServer } from 'node:http';\nimport { json } from 'milliparsec';\n\n// Define a basic type for the request body for TypeScript clarity\ninterface ReqWithBody extends Request {\n  body?: object;\n}\n\nconst server = createServer(async (req: ReqWithBody, res) => {\n  if (req.method === 'POST' && req.url === '/parse-json') {\n    await json()(req, res, (err) => {\n      if (err) {\n        console.error('Error parsing JSON:', err);\n        res.statusCode = 400;\n        return res.end(JSON.stringify({ error: err.message }));\n      }\n    });\n    res.setHeader('Content-Type', 'application/json');\n    res.end(JSON.stringify({ message: 'JSON parsed successfully', body: req.body }));\n  } else {\n    res.statusCode = 200;\n    res.setHeader('Content-Type', 'text/plain');\n    res.end('Send a POST request to /parse-json with a JSON body.');\n  }\n});\n\nconst PORT = process.env.PORT ?? 3000;\nserver.listen(PORT, () => {\n  console.log(`Server listening on http://localhost:${PORT}`);\n});\n\n// Example of how to test with curl:\n// curl -X POST -H \"Content-Type: application/json\" -d '{\"hello\": \"world\"}' http://localhost:3000/parse-json","lang":"typescript","description":"Demonstrates setting up an HTTP server with Node.js and `milliparsec` to parse a JSON request body using the `json` middleware. It includes basic error handling and type annotations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}