Skip to content

Commit

Permalink
docs: update documentation for res.type() (#1783)
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Popp <dustinpopp@ibm.com>
  • Loading branch information
dpopp07 authored Feb 11, 2025
1 parent 7e89208 commit d63a98b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions _includes/api/en/4x/res-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ res.type('application/json')
res.type('png')
// => 'image/png'
```

Aliased as `res.contentType(type)`.
4 changes: 3 additions & 1 deletion _includes/api/en/5x/res-type.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3 id='res.type'>res.type(type)</h3>

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.
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.

```js
res.type('.html') // => 'text/html'
Expand All @@ -9,3 +9,5 @@ res.type('json') // => 'application/json'
res.type('application/json') // => 'application/json'
res.type('png') // => image/png:
```

Aliased as `res.contentType(type)`.
15 changes: 15 additions & 0 deletions en/guide/migrating-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ You can then run your automated tests to see what fails, and fix problems accord
<li><a href="#res.send.body">res.send(body, status)</a></li>
<li><a href="#res.send.status">res.send(status)</a></li>
<li><a href="#res.sendfile">res.sendfile()</a></li>
<li><a href="#express.static.mime">express.static.mime</a></li>
</ul>

**Changed**
Expand Down Expand Up @@ -262,6 +263,20 @@ app.get('/user', (req, res) => {
})
```

<h4 id="express.static.mime">express.static.mime</h4>

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.

```js
// v4
express.static.mime.lookup('json')

// v5
const mime = require('mime-types')
mime.lookup('json')
```

<h3>Changed</h3>

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

0 comments on commit d63a98b

Please sign in to comment.