You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can then run your automated tests to see what fails, and fix problems according to the updates listed below. After addressing test failures, run your app to see what errors occur. You'll find out right away if the app uses any methods or properties that are not supported.
23
23
24
+
## Express 5 Codemods
25
+
26
+
To help you migrate your express server, we have created a set of codemods that will help you automatically update your code to the latest version of Express.
27
+
28
+
Run the following command for run all the codemods available:
29
+
30
+
```sh
31
+
npx @expressjs/codemod upgrade
32
+
```
33
+
34
+
If you want to run a specific codemod, you can run the following command:
35
+
36
+
```sh
37
+
npx @expressjs/codemod name-of-the-codemod
38
+
```
39
+
40
+
You can find the list of available codemods [here](https://github.com/expressjs/codemod?tab=readme-ov-file#available-codemods).
41
+
24
42
<h2id="changes">Changes in Express 5</h2>
25
43
26
44
**Removed methods and properties**
@@ -74,6 +92,16 @@ Express 5 no longer supports the `app.del()` function. If you use this function,
74
92
75
93
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.
76
94
95
+
{% capture codemod-deprecated-signatures %}
96
+
You can replace the deprecated signatures with the following command:
97
+
98
+
```plain-text
99
+
npx @expressjs/codemod v4-deprecated-signatures
100
+
```
101
+
{% endcapture %}
102
+
103
+
{% include admonitions/note.html content=codemod-deprecated-signatures %}
104
+
77
105
```js
78
106
// v4
79
107
app.del('/user/:id', (req, res) => {
@@ -100,6 +128,16 @@ The following method names have been pluralized. In Express 4, using the old met
100
128
101
129
`req.acceptsLanguage()` is replaced by `req.acceptsLanguages()`.
102
130
131
+
{% capture codemod-pluralized-methods %}
132
+
You can replace the deprecated signatures with the following command:
133
+
134
+
```plain-text
135
+
npx @expressjs/codemod pluralized-methods
136
+
```
137
+
{% endcapture %}
138
+
139
+
{% include admonitions/note.html content=codemod-pluralized-methods %}
140
+
103
141
```js
104
142
// v4
105
143
app.all('/', (req, res) => {
@@ -130,6 +168,16 @@ This should not affect your code if you follow the Express 4 documentation of [a
130
168
131
169
This potentially confusing and dangerous method of retrieving form data has been removed. You will now need to specifically look for the submitted parameter name in the `req.params`, `req.body`, or `req.query` object.
132
170
171
+
{% capture codemod-req-param %}
172
+
You can replace the deprecated signatures with the following command:
173
+
174
+
```plain-text
175
+
npx @expressjs/codemod req-param
176
+
```
177
+
{% endcapture %}
178
+
179
+
{% include admonitions/note.html content=codemod-req-param %}
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)`.
156
204
205
+
{% include admonitions/note.html content=codemod-deprecated-signatures %}
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)`.
172
222
223
+
{% include admonitions/note.html content=codemod-deprecated-signatures %}
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.
205
259
260
+
{% capture codemod-magic-redirect %}
261
+
You can replace the deprecated signatures with the following command:
262
+
263
+
```plain-text
264
+
npx @expressjs/codemod magic-redirect
265
+
```
266
+
{% endcapture %}
267
+
268
+
{% include admonitions/note.html content=codemod-magic-redirect %}
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)`.
221
285
286
+
{% include admonitions/note.html content=codemod-deprecated-signatures %}
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.
237
303
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.
238
304
305
+
{% include admonitions/note.html content=codemod-deprecated-signatures %}
0 commit comments