You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `res.sendfile()` function has been replaced by a camel-cased version `res.sendFile()` in Express 5.
324
324
325
+
**Note:** In Express 5, `res.sendFile()` uses the `mime-types` package for MIME type detection, which returns different Content-Type values than Express 4 for several common file types:
326
+
327
+
- JavaScript files (.js): now "text/javascript" instead of "application/javascript"
328
+
- JSON files (.json): now "application/json" instead of "text/json"
329
+
- CSS files (.css): now "text/css" instead of "text/plain"
330
+
- XML files (.xml): now "application/xml" instead of "text/xml"
331
+
- Font files (.woff): now "font/woff" instead of "application/font-woff"
332
+
- SVG files (.svg): now "image/svg+xml" instead of "application/svg+xml"
333
+
325
334
{% include admonitions/note.html content=codemod-deprecated-signatures %}
326
335
327
336
```js
@@ -345,6 +354,15 @@ The `router.param(fn)` signature was used for modifying the behavior of the `rou
345
354
In Express 5, `mime` is no longer an exported property of the `static` field.
346
355
Use the [`mime-types` package](https://github.com/jshttp/mime-types) to work with MIME type values.
347
356
357
+
**Important:** This change affects not only direct usage of `express.static.mime` but also other Express methods that rely on MIME type detection, such as `res.sendFile()`. The following MIME types have changed from Express 4:
358
+
359
+
- JavaScript files (.js): now served as "text/javascript" instead of "application/javascript"
360
+
- JSON files (.json): now served as "application/json" instead of "text/json"
361
+
- CSS files (.css): now served as "text/css" instead of "text/plain"
362
+
- HTML files (.html): now served as "text/html; charset=utf-8" instead of just "text/html"
363
+
- XML files (.xml): now served as "application/xml" instead of "text/xml"
364
+
- Font files (.woff): now served as "font/woff" instead of "application/font-woff"
`*splat` matches any path without the root path. If you need to match the root path as well `/`, you can use `/{*splat}`, wrapping the wildcard in braces.
415
+
`*splat` matches any path without the root path. If you need to match the root path as well `/`, you can use `/{*splat}`, wrapping the wildcard in braces.
0 commit comments