Registry / http-networking / lws-body-parser

lws-body-parser

JSON →
library3.0.1jsnpmunverified

Body parsing middleware for lws (local-web-server) that wraps koa-bodyparser. Version 3.0.1 is the latest stable release, requiring Node >=12.17. It provides body parsing for incoming HTTP requests, supporting JSON, URL-encoded, and multipart form data. Key differentiator: integration with lws middleware stack, providing a simple configuration-based approach compared to raw koa-bodyparser. Releases follow lws versioning cadence, with updates primarily driven by underlying koa-bodyparser changes.

npm install lws-body-parser
INSTALL
IMPORT
SIG · LWS-BODY-PARSER
L
lws-body-parser
http-networkingjavascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
import bodyParser from 'lws-body-parser'
const { bodyParser } = require('lws-body-parser')
ESM-only since v3. Default export is a function. CJS require() will fail without dynamic import.
class usage with lws
import { createServer } from 'lws' import bodyParser from 'lws-body-parser' const server = createServer() server.use(bodyParser)
const lws = require('lws'); const bodyParser = require('lws-body-parser').default;
Use ESM imports. In lws, add middleware via .use().
type imports
import type { BodyParserOptions } from 'lws-body-parser'
TypeScript users should import types separately. Not available in CJS.

Creates an lws server with body-parser middleware. Parses request body and echoes it back. Shows ESM import and basic middleware setup.

import { createServer } from 'lws' import bodyParser from 'lws-body-parser' const server = createServer() server.use(bodyParser) server.use((ctx) => { ctx.body = `Received: ${JSON.stringify(ctx.request.body)}` }) server.listen(8000, () => { console.log('Server running on http://localhost:8000') })
Debug
Known issues
breakingv3 dropped CommonJS support. Require() will throw a MODULE_NOT_FOUND error.
fix
Migrate to ESM: use 'import' instead of 'require()'.
affects: >=3.0.0
gotchaBody parsing only applies to requests with content-type application/json, application/x-www-form-urlencoded, or multipart/form-data.
fix
Ensure incoming requests have the correct Content-Type header. For custom types, configure koa-bodyparser options via lws-body-parser.
affects: >=2.0.0
deprecatedOptions passed to lws-body-parser may change in future versions to align with koa-bodyparser updates.
fix
Check official lws-body-parser docs for options; avoid depending on undocumented koa-bodyparser options.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
Using require() with an ESM-only package (lws-body-parser v3).
fix
Use import() or switch to ESM: 'import bodyParser from "lws-body-parser"' and set "type": "module" in package.json.
TypeError: ctx.request.body is undefined
Request body not parsed because content-type is missing or not supported.
fix
Ensure request has proper Content-Type header (e.g., application/json). Verify body-parser middleware is added before route handlers.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
koa-bodyparserrequiredprovides core body parsing functionality
Agent activity
2 hits · last 30 days
node
2
Resources
lws-body-parser — npm install lws-body-parser · libregistry