Skip to content

Releases: expressjs/codemod

v5-migration-recipe@1.0.0

13 Jan 15:59
Immutable release. Only release title and notes can be modified.
add40f7

Choose a tag to compare

Migrate recipes for Express.js v5

This codemod migration recipe helps you update your Express.js v4 applications to be compatible with Express.js v5 by addressing deprecated APIs.

Included transformations:

References

route-del-to-delete@1.0.0

13 Jan 15:00
Immutable release. Only release title and notes can be modified.
ce5c9ad

Choose a tag to compare

Migrate legacy app.del() to app.delete()

Migrates usage of the legacy APIs app.del() to app.delete().
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. The app.del() method was deprecated in Express 4 and removed in Express 5.

Example

Migrating app.del()

The migration involves replacing instances of app.del() with app.delete().

- app.del('/some-route', (req, res) => {
+ app.delete('/some-route', (req, res) => {
    // Some logic here
 });

References

redirect-arg-order@1.0.0

13 Jan 15:10
Immutable release. Only release title and notes can be modified.
a0a45a0

Choose a tag to compare

Migrate legacy res.redirect(url, status)

Migrates usage of the legacy APIs res.redirect(url, status) to the new signature
res.redirect(status, url). This usage was deprecated in Express 4, in Express 5 you must use the new signature res.redirect(status, url).

Example

Migrating res.redirect(url, status)

The migration involves replacing instances of res.redirect(url, status) with res.redirect(status, url).

app.get('/some-route', (req, res) => {
  // Some logic here
- res.redirect(url, status);
+ res.redirect(status, url);
});

References

explicit-request-params@1.0.0

13 Jan 15:34
Immutable release. Only release title and notes can be modified.
5464214

Choose a tag to compare

Migrate legacy req.param(name)

The req.param(name) helper that used to magically look up values from multiple places has been removed. 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.

Examples

Replacing req.param('body') and req.param('query')

Replace req.param('body') with req.body and
req.param('query') with req.query.

app.get('/', (req, res) => {
  // Before
- const reqBody = req.param('body');
- const reqQuery = req.param('query');
  // After
+ const reqBody = req.body;
+ const reqQuery = req.query;
});

Replacing req.param('paramName')

Replace req.param('paramName') with req.params.paramName.

app.get('/user/:id', (req, res) => {
  // Before
- const userId = req.param('id');
  // After
+ const userId = req.params.id;
});

References

status-send-order@1.0.0

09 Jan 22:43
Immutable release. Only release title and notes can be modified.
5856cfd

Choose a tag to compare

Migrate legacy res.send(obj, status), res.send(status), res.json(obj, status) and res.jsonp(obj, status)

Migrates usage of the legacy APIs res.send(obj, status), res.json(obj, status), and res.jsonp(obj, status) to use the recommended approach of specifying the status code
using the res.status(status).send(obj), res.status(status).json(obj), and
res.status(status).jsonp(obj) methods respectively. The older APIs that allowed
specifying the status code as a second argument have been deprecated.

Example

Migrating res.send(obj, status)

The migration involves replacing instances of res.send(obj, status) with res.status(status).send(obj).

app.get('/some-route', (req, res) => {
  // Some logic here
- res.send(obj, status);
+ res.status(status).send(obj);
});

Migrating res.json(obj, status)

The migration involves replacing instances of res.json(obj, status) with res.status(status).json(obj).

app.get('/some-route', (req, res) => {
  // Some logic here
- res.json(obj, status);
+ res.status(status).json(obj);
});

Migrating res.jsonp(obj, status)

The migration involves replacing instances of res.jsonp(obj, status) with res.status(status).jsonp(obj).

app.get('/some-route', (req, res) => {
  // Some logic here
- res.jsonp(obj, status);
+ res.status(status).jsonp(obj);
});

Migrating res.send(status)

The migration involves replacing instances of res.send(status) with res.sendStatus(status).

app.get('/some-route', (req, res) => {
  // Some logic here
- res.send(status);
+ res.sendStatus(status);
});

References

pluralize-method-names@1.0.0

09 Jan 22:46
Immutable release. Only release title and notes can be modified.
d9782a6

Choose a tag to compare

Migrate pluralized request methods

Migrates deprecated request methods to their pluralized versions that were deprecated in Express 4 and removed in Express 5.

Example

Migrating req.acceptsCharset(charset)

The migration involves replacing instances of req.acceptsCharset(charset) with req.acceptsCharsets(charset).

app.get('/', (req, res) => {
- const charset = req.acceptsCharset('utf-8');
+ const charset = req.acceptsCharsets('utf-8');
  res.json({ charset });
});

Migrating `req.acceptsEncoding(encoding)

The migration involves replacing instances of req.acceptsEncoding(encoding) with req.acceptsEncodings(encoding).

app.get('/', (req, res) => {
- const encoding = req.acceptsEncoding('gzip');
+ const encoding = req.acceptsEncodings('gzip');
  res.json({ encoding });
});

Migrating req.acceptsLanguage(language)

The migration involves replacing instances of req.acceptsLanguage(language) with req.acceptsLanguages(language).

app.get('/', (req, res) => {
- const language = req.acceptsLanguage('en');
+ const language = req.acceptsLanguages('en');
  res.json({ language });
});

References

camelcase-sendfile@1.0.0

09 Jan 22:41
Immutable release. Only release title and notes can be modified.
8e20937

Choose a tag to compare

Migrate legacy res.sendfile(file) to res.sendFile(file)

Migrates usage of the legacy APIs res.sendfile(file) to res.sendFile(file).

Example

Migrating res.sendfile(file)

The migration involves replacing instances of res.sendfile(file) with res.sendFile(file).

app.get('/some-route', (req, res) => {
  // Some logic here
- res.sendfile('/path/to/file');
+ res.sendFile('/path/to/file');
});

References

back-redirect-deprecated@1.0.0

06 Jan 23:46
35e5d27

Choose a tag to compare

Migrate legacy res.redirect('back') and res.location('back')

Migrates usage of the legacy APIs res.redirect('back') and res.location('back')
to use the recommended approach of accessing the Referer header directly from
the request object. Versions of Express before 5 allowed the use of the string
"back" as a shortcut to redirect to the referring page, but this has been
deprecated.

Example

Migrating res.redirect('back')

The migration involves replacing instances of res.redirect('back') with res.redirect(req.get('Referer') || '/').

app.get('/some-route', (req, res) => {
  // Some logic here
- res.redirect('back');
+ res.redirect(req.get('Referer') || '/');
});

Migrating res.location('back')

The migration involves replacing instances of res.location('back') with res.location(req.get('Referer') || '/').

app.get('/some-route', (req, res) => {
  // Some logic here
- res.location('back');
+ res.location(req.get('Referer') || '/');
});

References

v0.0.5

01 Jun 21:21
df7e3b3

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.0.4...v0.0.5

v0.0.4

29 Mar 19:46
d2bb22d

Choose a tag to compare

What's Changed

Full Changelog: v0.0.3...v0.0.4