Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions en/guide/migrating-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ To help you migrate your express server, we have created a set of codemods that
Run the following command for run all the codemods available:

```sh
npx @expressjs/codemod upgrade
npx codemod@latest @expressjs/v5/migration-recipe
```

If you want to run a specific codemod, you can run the following command:

```sh
npx @expressjs/codemod name-of-the-codemod
npx codemod@latest @expressjs/name-of-the-codemod
```

You can find the list of available codemods [here](https://github.com/expressjs/codemod?tab=readme-ov-file#available-codemods).
Expand Down Expand Up @@ -97,15 +97,15 @@ Express 5 no longer supports the `app.del()` function. If you use this function,

Initially, `del` was used instead of `delete`, because `delete` is a reserved keyword in JavaScript. However, as of ECMAScript 6, `delete` and other reserved keywords can legally be used as property names.

{% capture codemod-deprecated-signatures %}
{% capture codemod-route-del-to-delete %}
You can replace the deprecated signatures with the following command:

```plain-text
npx @expressjs/codemod v4-deprecated-signatures
npx codemod@latest @expressjs/route-del-to-delete
```
{% endcapture %}

{% include admonitions/note.html content=codemod-deprecated-signatures %}
{% include admonitions/note.html content=codemod-route-del-to-delete %}

```js
// v4
Expand Down Expand Up @@ -137,7 +137,7 @@ The following method names have been pluralized. In Express 4, using the old met
You can replace the deprecated signatures with the following command:

```plain-text
npx @expressjs/codemod pluralized-methods
npx codemod@latest @expressjs/pluralize-method-names
```
{% endcapture %}

Expand Down Expand Up @@ -177,7 +177,7 @@ This potentially confusing and dangerous method of retrieving form data has been
You can replace the deprecated signatures with the following command:

```plain-text
npx @expressjs/codemod req-param
npx codemod@latest @expressjs/req-param
```
{% endcapture %}

Expand Down Expand Up @@ -207,7 +207,15 @@ app.post('/user', (req, res) => {

Express 5 no longer supports the signature `res.json(obj, status)`. Instead, set the status and then chain it to the `res.json()` method like this: `res.status(status).json(obj)`.

{% include admonitions/note.html content=codemod-deprecated-signatures %}
{% capture codemod-status-send-order %}
You can replace the deprecated signatures with the following command:

```plain-text
npx codemod@latest @expressjs/status-send-order
```
{% endcapture %}

{% include admonitions/note.html content=codemod-status-send-order %}

```js
// v4
Expand All @@ -225,7 +233,8 @@ app.post('/user', (req, res) => {

Express 5 no longer supports the signature `res.jsonp(obj, status)`. Instead, set the status and then chain it to the `res.jsonp()` method like this: `res.status(status).jsonp(obj)`.

{% include admonitions/note.html content=codemod-deprecated-signatures %}
{% include admonitions/note.html content=codemod-status-send-order %}


```js
// v4
Expand All @@ -243,7 +252,15 @@ app.post('/user', (req, res) => {

Express 5 no longer supports the signature `res.redirect(url, status)`. Instead, use the following signature: `res.redirect(status, url)`.

{% include admonitions/note.html content=codemod-deprecated-signatures %}
{% capture codemod-redirect-arg-order %}
You can replace the deprecated signatures with the following command:

```plain-text
npx codemod@latest @expressjs/redirect-arg-order
```
{% endcapture %}

{% include admonitions/note.html content=codemod-redirect-arg-order %}

```js
// v4
Expand All @@ -262,15 +279,15 @@ app.get('/user', (req, res) => {

Express 5 no longer supports the magic string `back` in the `res.redirect()` and `res.location()` methods. Instead, use the `req.get('Referrer') || '/'` value to redirect back to the previous page. In Express 4, the `res.redirect('back')` and `res.location('back')` methods were deprecated.

{% capture codemod-magic-redirect %}
{% capture codemod-back-redirect-deprecated %}
You can replace the deprecated signatures with the following command:

```plain-text
npx @expressjs/codemod magic-redirect
npx codemod@latest @expressjs/back-redirect-deprecated
```
{% endcapture %}

{% include admonitions/note.html content=codemod-magic-redirect %}
{% include admonitions/note.html content=codemod-back-redirect-deprecated %}

```js
// v4
Expand All @@ -288,7 +305,8 @@ app.get('/user', (req, res) => {

Express 5 no longer supports the signature `res.send(obj, status)`. Instead, set the status and then chain it to the `res.send()` method like this: `res.status(status).send(obj)`.

{% include admonitions/note.html content=codemod-deprecated-signatures %}
{% include admonitions/note.html content=codemod-status-send-order %}


```js
// v4
Expand All @@ -307,7 +325,8 @@ app.get('/user', (req, res) => {
Express 5 no longer supports the signature `res.send(status)`, where `status` is a number. Instead, use the `res.sendStatus(statusCode)` function, which sets the HTTP response header status code and sends the text version of the code: "Not Found", "Internal Server Error", and so on.
If you need to send a number by using the `res.send()` function, quote the number to convert it to a string, so that Express does not interpret it as an attempt to use the unsupported old signature.

{% include admonitions/note.html content=codemod-deprecated-signatures %}
{% include admonitions/note.html content=codemod-status-send-order %}


```js
// v4
Expand All @@ -334,7 +353,15 @@ The `res.sendfile()` function has been replaced by a camel-cased version `res.se
- Font files (.woff): now "font/woff" instead of "application/font-woff"
- SVG files (.svg): now "image/svg+xml" instead of "application/svg+xml"

{% include admonitions/note.html content=codemod-deprecated-signatures %}
{% capture codemod-camelcase-sendfile %}
You can replace the deprecated signatures with the following command:

```plain-text
npx codemod@latest @expressjs/camelcase-sendfile
```
{% endcapture %}

{% include admonitions/note.html content=codemod-camelcase-sendfile %}

```js
// v4
Expand Down