-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs: clarify MIME type changes when migrating from Express 4 to 5 #1903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for expressjscom-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@bjohansebas I have added it back |
en/guide/migrating-5.md
Outdated
@@ -345,6 +345,8 @@ The `router.param(fn)` signature was used for modifying the behavior of the `rou | |||
In Express 5, `mime` is no longer an exported property of the `static` field. | |||
Use the [`mime-types` package](https://github.com/jshttp/mime-types) to work with MIME type values. | |||
|
|||
**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()`. For example, JavaScript files (.js) will now be served with the MIME type "text/javascript" instead of "application/javascript" as in Express 4. Other file types may also have different MIME types than before. If your application depends on specific MIME types, you should test thoroughly after upgrading. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend listing the MIME types that changed, instead of saying “try which ones changed.”
en/guide/migrating-5.md
Outdated
<h4 id="res.sendfile">res.sendfile()</h4> | ||
|
||
The `res.sendfile()` function has been replaced by a camel-cased version `res.sendFile()` in Express 5. | ||
|
||
**Note:** In Express 5, `res.sendFile()` uses the `mime-types` package for MIME type detection, which may return different Content-Type values than Express 4 did. For example, JavaScript files (.js) will now be served with "text/javascript" instead of "application/javascript". If your application depends on specific MIME types, you should test thoroughly after upgrading. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjohansebas I have done the changes you asked me to do. |
This PR improves the Express 5 migration guide by documenting an important change in MIME type handling that affects users migrating from Express 4 to Express 5.
Issue #1880
When migrating from Express 4 to Express 5, we discovered that JavaScript files served via
res.sendFile()
now return a Content-Type of "text/javascript" instead of the previous "application/javascript". This change occurs because Express 5 switched from its internal MIME type handling to themime-types
package.Changes
express.static.mime
section explaining that this change affects other methods likeres.sendFile()
res.sendfile()
section warning about potential Content-Type differencesThese documentation improvements will help users understand and prepare for potential MIME type differences when upgrading to Express 5, even if they weren't directly using
express.static.mime
.Developer's Certificate of Origin 1.1 is acknowledged and agreed to.