urlencoded-body-parser is a minimalist JavaScript library designed for parsing `application/x-www-form-urlencoded` request bodies into JavaScript objects. It leverages the `qs` library internally for robust query string parsing. The current stable version is 3.0.0. The project maintains an irregular release cadence, with major versions typically introducing breaking API changes, such as the transition to a Promise-based API in v2.0.0. Its primary differentiator is its small footprint and straightforward, promise-returning API, making it suitable for lightweight HTTP servers and microservices, particularly those built with Node.js's `http` module or frameworks like Micro. It offers a `parse` function that takes an `http.IncomingMessage` and an optional `limit` parameter to prevent excessive memory usage, returning the parsed data as a Promise.
npm install urlencoded-body-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic Node.js HTTP server to parse `application/x-www-form-urlencoded` POST requests using `urlencoded-body-parser`, including error handling and body size limiting.
Update all calls to `parse(req)` to use `await parse(req)` or `parse(req).then(data => ...)` to handle the returned Promise.
Always use `await parse(req)` inside an `async` function or `parse(req).then(...)` to correctly resolve the Promise and access the parsed data.
Configure the `limit` option (e.g., `parse(req, { limit: '5mb' })`) if you expect larger payloads, or ensure proper error handling for payload too large errors.The `parse` function in versions >=2.0.0 returns a Promise. Change your code to `await parse(req)` or `parse(req).then(data => ...)`.
Ensure that you `await parse(req)` in an `async` function or handle the Promise resolution using `.then()` and `.catch()`.
Increase the `limit` option in `parse(req, { limit: '2mb' })` or handle the error gracefully, returning an appropriate HTTP status like 413 Payload Too Large.