Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,25 @@ exports = module.exports = bodyParser
* JSON parser.
* @public
*/
Object.defineProperty(exports, 'json', {
configurable: true,
enumerable: true,
get: () => require('./lib/types/json')
})
exports.json = require('./lib/types/json')

/**
* Raw parser.
* @public
*/
Object.defineProperty(exports, 'raw', {
configurable: true,
enumerable: true,
get: () => require('./lib/types/raw')
})
exports.raw = require('./lib/types/raw')

/**
* Text parser.
* @public
*/
Object.defineProperty(exports, 'text', {
configurable: true,
enumerable: true,
get: () => require('./lib/types/text')
})
exports.text = require('./lib/types/text')

/**
* URL-encoded parser.
* @public
*/
Object.defineProperty(exports, 'urlencoded', {
configurable: true,
enumerable: true,
get: () => require('./lib/types/urlencoded')
})
exports.urlencoded = require('./lib/types/urlencoded')

/**
* Create a middleware to parse json and urlencoded bodies.
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
"type": "opencollective",
"url": "https://opencollective.com/express"
},
"exports": {
".": "./index.js",
"./package.json": "./package.json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it be necessary to add the package.json?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added ./package.json to the exports field to avoid breaking existing tooling and user setups that rely on require('body-parser/package.json') to read metadata (e.g. version info). Once exports is defined, Node.js treats it as an allowlist, so this preserves backward compatibility.

Docs: https://nodejs.org/api/packages.html#package-entry-points

"./json": "./lib/types/json.js",
"./raw": "./lib/types/raw.js",
"./text": "./lib/types/text.js",
"./urlencoded": "./lib/types/urlencoded.js"
},
"dependencies": {
"bytes": "^3.1.2",
"content-type": "^1.0.5",
Expand Down