Skip to content
14 changes: 14 additions & 0 deletions docs/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ src/content/api/
- Versioned: `/en/5x/api/application` → Express 5.x application API
- Non-versioned: `/en/api/application` → Defaults to Express 5.x

### Style Conventions

The reference pages for every version follow the same conventions, so that switching between
Express 4.x and 5.x only shows real API differences:

- Property and method sections are listed alphabetically, so `req.host` comes before `req.hostname`.
- Result comments in code samples use single quotes, matching the Prettier `singleQuote` setting:
`res.type('png'); // => 'image/png'`. Double quotes are kept only where the sample shows JSON or a
raw HTTP header.
- The frontmatter `description` of the request and response pages repeats the opening sentence of the
page, which refers to the objects as `req` and `res` rather than spelling out their full names.

`tests/unit/api-docs-style.test.mjs` checks these conventions, and it runs as part of `npm run test:unit`.

## Versioning

The Express.js documentation supports multiple versions. Content is organized by version in both the `docs` and `api` collections.
Expand Down
2 changes: 1 addition & 1 deletion src/content/api/4x/api/application/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ app.get('title');

app.set('title', 'My Site');
app.get('title');
// => "My Site"
// => 'My Site'
```

### app.get()
Expand Down
54 changes: 27 additions & 27 deletions src/content/api/4x/api/request/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ console.dir(req.fresh);
// => true
```

### req.host

<Signature type="String" deprecated="v4.5.0" />

<Alert type="alert">

`req.host` is a deprecated alias of [`req.hostname`](#reqhostname) and returns the same value — the hostname with the port number stripped off. It has emitted a deprecation warning since Express v4.5.0. Use `req.hostname` instead.

</Alert>

```js
// Host: "example.com:3000"
console.dir(req.host);
// => 'example.com'
```

### req.hostname

<Signature type="String" />
Expand Down Expand Up @@ -272,22 +288,6 @@ console.dir(req.hostname);
// => 'example.com'
```

### req.host

<Signature type="String" deprecated="v4.5.0" />

<Alert type="alert">

`req.host` is a deprecated alias of [`req.hostname`](#reqhostname) and returns the same value — the hostname with the port number stripped off. It has emitted a deprecation warning since Express v4.5.0. Use `req.hostname` instead.

</Alert>

```js
// Host: "example.com:3000"
console.dir(req.host);
// => 'example.com'
```

### req.ip

<Signature type="String" />
Expand Down Expand Up @@ -671,17 +671,17 @@ list or array, the method returns the _best_ match (if any).
```js
// Accept: text/html
req.accepts('html');
// => "html"
// => 'html'

// Accept: text/*, application/json
req.accepts('html');
// => "html"
// => 'html'
req.accepts('text/html');
// => "text/html"
// => 'text/html'
req.accepts(['json', 'text']);
// => "json"
// => 'json'
req.accepts('application/json');
// => "application/json"
// => 'application/json'

// Accept: text/*, application/json
req.accepts('image/png');
Expand All @@ -690,7 +690,7 @@ req.accepts('png');

// Accept: text/*;q=.5, application/json
req.accepts(['html', 'json']);
// => "json"
// => 'json'
```

For more information, or if you have issues or concerns, see [accepts](https://github.com/expressjs/accepts).
Expand Down Expand Up @@ -856,10 +856,10 @@ The `Referrer` and `Referer` fields are interchangeable.

```js
req.get('Content-Type');
// => "text/plain"
// => 'text/plain'

req.get('content-type');
// => "text/plain"
// => 'text/plain'

req.get('Something');
// => undefined
Expand Down Expand Up @@ -943,15 +943,15 @@ Returns the value of param `name` when present.
```js
// ?name=tobi
req.param('name');
// => "tobi"
// => 'tobi'

// POST name=tobi
req.param('name');
// => "tobi"
// => 'tobi'

// /user/tobi for /user/:name
req.param('name');
// => "tobi"
// => 'tobi'
```

Lookup is performed in the following order:
Expand Down
2 changes: 1 addition & 1 deletion src/content/api/4x/api/response/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ The match is case-insensitive.

```js
res.get('Content-Type');
// => "text/plain"
// => 'text/plain'
```

### res.json()
Expand Down
2 changes: 1 addition & 1 deletion src/content/api/5x/api/application/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ app.get('title');

app.set('title', 'My Site');
app.get('title');
// => "My Site"
// => 'My Site'
```

### app.get()
Expand Down
38 changes: 19 additions & 19 deletions src/content/api/5x/api/request/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Request Object
description: The request object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on
description: The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on
---

import Alert from '@components/primitives/Alert/Alert.astro';
Expand Down Expand Up @@ -211,7 +211,7 @@ contains cookies sent by the request. If the request contains no cookies, it def
```js
// Cookie: name=tj
console.dir(req.cookies.name);
// => "tj"
// => 'tj'
```

If the cookie has been signed, you have to use [req.signedCookies](#reqsignedcookies).
Expand Down Expand Up @@ -292,7 +292,7 @@ the value of this property is derived from the left-most entry in the

```js
console.dir(req.ip);
// => "127.0.0.1"
// => '127.0.0.1'
```

### req.ips
Expand Down Expand Up @@ -361,7 +361,7 @@ the "mounting" feature of [app.use()](/api/application/#appuse) will rewrite `re
```js
// GET /search?q=something
console.dir(req.originalUrl);
// => "/search?q=something"
// => '/search?q=something'
```

`req.originalUrl` is available both in middleware and router objects, and is a
Expand Down Expand Up @@ -398,7 +398,7 @@ This property is an object containing properties mapped to the [named route "par
```js
// GET /user/tj
console.dir(req.params.name);
// => "tj"
// => 'tj'
```

Properties corresponding to wildcard parameters are arrays containing separate path segments split on `/`:
Expand Down Expand Up @@ -433,7 +433,7 @@ When you use a regular expression for the route definition, capture groups are p
app.use(/^\/file\/(.*)$/, (req, res) => {
// GET /file/javascripts/jquery.js
console.dir(req.params[0]);
// => "javascripts/jquery.js"
// => 'javascripts/jquery.js'
});
```

Expand All @@ -443,7 +443,7 @@ import { type Request, type Response } from 'express';
app.use(/^\/file\/(.*)$/, (req: Request, res: Response) => {
// GET /file/javascripts/jquery.js
console.dir(req.params[0]);
// => "javascripts/jquery.js"
// => 'javascripts/jquery.js'
});
```

Expand All @@ -468,7 +468,7 @@ Contains the path part of the request URL.
```js
// example.com/users?sort=desc
console.dir(req.path);
// => "/users"
// => '/users'
```

<Alert type="info">
Expand All @@ -490,7 +490,7 @@ This header can be set by the client or by the proxy.

```js
console.dir(req.protocol);
// => "http"
// => 'http'
```

### req.query
Expand Down Expand Up @@ -637,7 +637,7 @@ If no signed cookies are sent, the property defaults to `{}`.
```js
// Cookie: user=tobi.CP7AWaXDfAKIRfH49dQzKJx7sKzzSoPq7/AcBBRVwlI3
console.dir(req.signedCookies.user);
// => "tobi"
// => 'tobi'
```

For more information, issues, or concerns, see [cookie-parser](https://github.com/expressjs/cookie-parser).
Expand All @@ -663,7 +663,7 @@ An array of subdomains in the domain name of the request.
```js
// Host: "tobi.ferrets.example.com"
console.dir(req.subdomains);
// => ["ferrets", "tobi"]
// => ['ferrets', 'tobi']
```

The application property `subdomain offset`, which defaults to 2, is used for determining the
Expand Down Expand Up @@ -708,17 +708,17 @@ list or array, the method returns the _best_ match (if any).
```js
// Accept: text/html
req.accepts('html');
// => "html"
// => 'html'

// Accept: text/*, application/json
req.accepts('html');
// => "html"
// => 'html'
req.accepts('text/html');
// => "text/html"
// => 'text/html'
req.accepts(['json', 'text']);
// => "json"
// => 'json'
req.accepts('application/json');
// => "application/json"
// => 'application/json'

// Accept: text/*, application/json
req.accepts('image/png');
Expand All @@ -727,7 +727,7 @@ req.accepts('png');

// Accept: text/*;q=.5, application/json
req.accepts(['html', 'json']);
// => "json"
// => 'json'
```

For more information, or if you have issues or concerns, see [accepts](https://github.com/expressjs/accepts).
Expand Down Expand Up @@ -832,10 +832,10 @@ The `Referrer` and `Referer` fields are interchangeable.

```js
req.get('Content-Type');
// => "text/plain"
// => 'text/plain'

req.get('content-type');
// => "text/plain"
// => 'text/plain'

req.get('Something');
// => undefined
Expand Down
6 changes: 3 additions & 3 deletions src/content/api/5x/api/response/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Response
description: The response object represents the HTTP response that an Express app sends when it gets an HTTP request.
description: The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
---

import Alert from '@components/primitives/Alert/Alert.astro';
Expand Down Expand Up @@ -564,7 +564,7 @@ The match is case-insensitive.

```js
res.get('Content-Type');
// => "text/plain"
// => 'text/plain'
```

### res.json()
Expand Down Expand Up @@ -1104,7 +1104,7 @@ res.type('.html'); // => 'text/html'
res.type('html'); // => 'text/html'
res.type('json'); // => 'application/json'
res.type('application/json'); // => 'application/json'
res.type('png'); // => image/png:
res.type('png'); // => 'image/png'
```

Aliased as `res.contentType(type)`.
Expand Down
Loading
Loading