@@ -55,10 +55,26 @@ The Express object has the following methods that can be used to create middlewa
5555 The ` reviver ` option is passed directly to ` JSON.parse ` as the second argument. You can
5656 find more information on this argument [ in the MDN documentation about
5757 JSON.parse] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter ) .
58+
59+ ``` js
60+ app .use (express .json ({
61+ reviver : (key , value ) => key === ' createdAt' ? new Date (value) : value,
62+ }));
63+ // Body: {"createdAt":"2026-01-01T00:00:00Z"}
64+ // req.body.createdAt is a Date.
65+ ```
66+
5867 </Param >
5968 <Param name = " strict" type = " Boolean" default = " true" >
6069 Enables or disables only accepting arrays and objects; when disabled will accept anything
6170 ` JSON.parse ` accepts.
71+
72+ ``` js
73+ app .use (express .json ({ strict: false }));
74+ // Body: 42 -> req.body is the number 42.
75+ // With strict: true (the default), this body is rejected with status 400.
76+ ```
77+
6278 </Param >
6379 <Param name = " type" type = " String | String[] | Function" default = ' "application/json"' >
6480 This is used to determine what media type the middleware will parse. This option can be a
@@ -72,6 +88,16 @@ The Express object has the following methods that can be used to create middlewa
7288 This option, if supplied, is called as ` verify(req, res, buf, encoding) ` , where ` buf ` is a
7389 ` Buffer ` of the raw request body and ` encoding ` is the encoding of the request. The
7490 parsing can be aborted by throwing an error.
91+
92+ ``` js
93+ app .use (express .json ({
94+ verify : (req , res , buf ) => {
95+ req .rawBody = buf;
96+ },
97+ }));
98+ // req.rawBody contains the original Buffer, before JSON parsing.
99+ ```
100+
75101 </Param >
76102 </Fragment >
77103 </Param >
@@ -249,15 +275,43 @@ app.post('/upload', (req: Request, res: Response) => {
249275 <Fragment slot = " attributes" >
250276 <Param name = " caseSensitive" type = " Boolean" default = " false" >
251277 Enable case sensitivity. Disabled by default, treating ` /Foo ` and ` /foo ` as the same.
278+
279+ ``` js
280+ // caseSensitive: treat "/Foo" and "/foo" as different routes
281+ const router = express .Router ({ caseSensitive: true });
282+ router .get (' /Foo' , (req , res ) => res .send (' Matched /Foo exactly' ));
283+ ```
284+
252285 </Param >
253286 <Param name = " mergeParams" type = " Boolean" default = " false" >
254287 Preserve the ` req.params ` values from the parent router. If the parent and the child have
255288 conflicting param names, the child's value take precedence.
289+
290+ ``` js
291+ // mergeParams: access parent route params in child router
292+ const parent = express .Router ();
293+ const child = express .Router ({ mergeParams: true });
294+
295+ parent .use (' /user/:userId' , child);
296+ child .get (' /comments' , (req , res ) => {
297+ // req.params.userId is available because mergeParams: true
298+ res .send (` Comments for user ${ req .params .userId } ` );
299+ });
300+ ```
301+
256302 </Param >
257303 <Param name = " strict" type = " Boolean" default = " false" >
258304 Enable strict routing. Disabled by default, ` /foo ` and ` /foo/ ` are treated the same by the
259305 router.
306+
307+ ``` js
308+ // strict: treat "/foo" and "/foo/" as different routes
309+ const strictRouter = express .Router ({ strict: true });
310+ strictRouter .get (' /foo/' , (req , res ) => res .send (' Matched /foo/ with trailing slash' ));
311+ ```
312+
260313 </Param >
314+
261315 </Fragment >
262316</Signature >
263317
@@ -304,12 +358,32 @@ For more information, see [Router](/api/router/).
304358 <Param name = " fallthrough" type = " Boolean" default = " true" >
305359 Let client errors fall-through as unhandled requests, otherwise forward a client error.
306360 See [ fallthrough] ( #fallthrough ) below.
361+
362+ ``` js
363+ app .use (' /assets' , express .static (' public' , { fallthrough: true }));
364+ app .use (' /assets' , (req , res ) => {
365+ res .status (404 ).send (' Asset not found' );
366+ });
367+ // Missing files reach the fallback above.
368+ // With fallthrough: false, they reach error-handling middleware instead.
369+ ```
370+
307371 </Param >
308372 <Param name = " immutable" type = " Boolean" default = " false" >
309373 Enable or disable the ` immutable ` directive in the ` Cache-Control ` response header. If
310374 enabled, the ` maxAge ` option should also be specified to enable caching. The ` immutable `
311375 directive will prevent supported clients from making conditional requests during the life
312376 of the ` maxAge ` option to check if the file has changed.
377+
378+ ``` js
379+ // Use filenames that change whenever the file contents change.
380+ app .use (' /assets' , express .static (' public' , {
381+ maxAge: ' 1y' ,
382+ immutable: true ,
383+ }));
384+ // Cache-Control: public, max-age=31536000, immutable
385+ ```
386+
313387 </Param >
314388 <Param name = " index" type = " String | Boolean" default = ' "index.html"' >
315389 Sends the specified directory index file. Set to ` false ` to disable directory indexing.
@@ -579,6 +653,18 @@ app.post('/', (req: Request, res: Response) => {
579653 rich objects and arrays to be encoded into the URL-encoded format, allowing for a
580654 JSON-like experience with URL-encoded. For more information, please [ see the qs
581655 library] ( https://www.npmjs.com/package/qs#readme ) .
656+
657+ ``` js
658+ // Form body: user[name]=Tobi
659+ app .post (' /simple' , express .urlencoded ({ extended: false }), (req , res ) => {
660+ res .json (req .body ); // => { 'user[name]': 'Tobi' }
661+ });
662+
663+ app .post (' /extended' , express .urlencoded ({ extended: true }), (req , res ) => {
664+ res .json (req .body ); // => { user: { name: 'Tobi' } }
665+ });
666+ ```
667+
582668 </Param >
583669 <Param name = " inflate" type = " Boolean" default = " true" >
584670 Enables or disables handling deflated (compressed) bodies; when disabled, deflated bodies
0 commit comments