Skip to content

Commit d63a98b

Browse files
author
Dustin Popp
authored
docs: update documentation for res.type() (#1783)
Signed-off-by: Dustin Popp <[email protected]>
1 parent 7e89208 commit d63a98b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

_includes/api/en/4x/res-type.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ res.type('application/json')
1414
res.type('png')
1515
// => 'image/png'
1616
```
17+
18+
Aliased as `res.contentType(type)`.

_includes/api/en/5x/res-type.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h3 id='res.type'>res.type(type)</h3>
22

3-
Sets the `Content-Type` HTTP header to the MIME type as determined by the specified `type`. If `type` contains the "/" character, then it sets the `Content-Type` to the exact value of `type`, otherwise it is assumed to be a file extension and the MIME type is looked up in a mapping using the `express.static.mime.lookup()` method.
3+
Sets the `Content-Type` HTTP header to the MIME type as determined by the specified `type`. If `type` contains the "/" character, then it sets the `Content-Type` to the exact value of `type`, otherwise it is assumed to be a file extension and the MIME type is looked up using the `contentType()` method of the `mime-types` package.
44

55
```js
66
res.type('.html') // => 'text/html'
@@ -9,3 +9,5 @@ res.type('json') // => 'application/json'
99
res.type('application/json') // => 'application/json'
1010
res.type('png') // => image/png:
1111
```
12+
13+
Aliased as `res.contentType(type)`.

en/guide/migrating-5.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ You can then run your automated tests to see what fails, and fix problems accord
3737
<li><a href="#res.send.body">res.send(body, status)</a></li>
3838
<li><a href="#res.send.status">res.send(status)</a></li>
3939
<li><a href="#res.sendfile">res.sendfile()</a></li>
40+
<li><a href="#express.static.mime">express.static.mime</a></li>
4041
</ul>
4142

4243
**Changed**
@@ -262,6 +263,20 @@ app.get('/user', (req, res) => {
262263
})
263264
```
264265

266+
<h4 id="express.static.mime">express.static.mime</h4>
267+
268+
In Express 5, `mime` is no longer an exported property of the `static` field.
269+
Use the [`mime-types` package](https://github.com/jshttp/mime-types) to work with MIME type values.
270+
271+
```js
272+
// v4
273+
express.static.mime.lookup('json')
274+
275+
// v5
276+
const mime = require('mime-types')
277+
mime.lookup('json')
278+
```
279+
265280
<h3>Changed</h3>
266281

267282
<h4 id="path-syntax">Path route matching syntax</h4>

0 commit comments

Comments
 (0)