Skip to content

Commit 9199b05

Browse files
committed
feat: add subpath exports for individual parsers
Add an exports field to package.json exposing json, raw, text, and urlencoded parsers as subpath exports. This allows consumers to import individual parsers directly: - CommonJS: require('body-parser/json') - ESM: import json from 'body-parser/json' The change is fully backward compatible and enables users to opt into loading only the parsers they need.
1 parent 9a058c7 commit 9199b05

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ unreleased
22
========================
33

44
* fix: use static exports instead of lazy getters to improve ESM compatibility
5+
* feat: add subpath exports for individual parsers
56

67
2.2.2 / 2026-01-07
78
=========================

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ $ npm install body-parser
5151
## API
5252

5353
```js
54+
// Import all parsers
5455
const bodyParser = require('body-parser')
56+
57+
// Or import individual parsers directly
58+
const json = require('body-parser/json')
59+
const urlencoded = require('body-parser/urlencoded')
60+
const raw = require('body-parser/raw')
61+
const text = require('body-parser/text')
5562
```
5663

5764
The `bodyParser` object exposes various factories to create middlewares. All

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
"type": "opencollective",
1313
"url": "https://opencollective.com/express"
1414
},
15+
"exports": {
16+
".": "./index.js",
17+
"./package.json": "./package.json",
18+
"./json": "./lib/types/json.js",
19+
"./raw": "./lib/types/raw.js",
20+
"./text": "./lib/types/text.js",
21+
"./urlencoded": "./lib/types/urlencoded.js",
22+
"./lib/*": "./lib/*.js",
23+
"./lib/*.js": "./lib/*.js",
24+
"./lib/types/*": "./lib/types/*.js",
25+
"./lib/types/*.js": "./lib/types/*.js"
26+
},
1527
"dependencies": {
1628
"bytes": "^3.1.2",
1729
"content-type": "^1.0.5",

0 commit comments

Comments
 (0)