-
- | Objet |
- Description |
-
-
- | Node.js |
- Express 4 requires Node.js 0.10.x or later and has dropped support for Node.js 0.8.x. |
-
-
- | `http.createServer()` |
-
- Le module `http` n'est plus nécessaire, à moins que vous ayez besoin de travailler directement
- avec lui (socket.io/SPDY/HTTPS). L'application peut être démarrée en utilisant la fonction
- `app.listen()`.
- |
-
-
- | `app.configure()` |
-
- La fonction `app.configure()` a été supprimée. Utilisez la fonction `process.env.NODE_ENV` ou
- `app.get('env')` pour détecter l'environnement et configurer l'application en conséquence.
- |
-
-
- | `json spaces` |
-
- La propriété `json spaces` de l'application est désactivée par défaut dans Express 4.
- |
-
-
- | `req.accepted()` |
-
- Utilisez `req.accepts()`, `req.acceptsEncodings()`, `req.acceptsCharsets()`, et
- `req.acceptsLanguages()`.
- |
-
-
- | `res.location()` |
- Ne résout plus les URL relatives. |
-
-
- | `req.params` |
- A été un tableau ; maintenant un objet. |
-
-
- | `res.locals` |
- Était une fonction ; maintenant un objet. |
-
-
- | `res.headerSent` |
- Changé en `res.headersSent`. |
-
-
- | `app.route` |
- Maintenant disponible en tant que `app.mountpath`. |
-
-
- | `res.on('header')` |
- Supprimé. |
-
-
- | `res.charset` |
- Supprimé. |
-
-
- | `res.setHeader('Set-Cookie', val)` |
-
- La fonctionnalité est maintenant limitée à définir la valeur de base des cookies. Utilisez
- `res.cookie()` pour ajouter une fonctionnalité .
- |
-
-
+| Object | Libellé |
+| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Node.js | Express 4 requires Node.js 0.10.x or later and has dropped support for Node.js 0.8.x. |
+| `http.createServer()` | The `http` module is no longer needed, unless you need to directly work with it (socket.io/SPDY/HTTPS). L'application peut être démarrée en utilisant la fonction
`app.listen()`. |
+| `app.configure()` | La fonction `app.configure()` a été supprimée. Utilisez la fonction `process.env.NODE_ENV` ou
`app.get('env')` pour détecter l'environnement et configurer l'application en conséquence. |
+| `json spaces` | La propriété `json spaces` de l'application est désactivée par défaut dans Express 4. |
+| `req.accepted()` | Utilisez `req.accepts()`, `req.acceptsEncodings()`, `req.acceptsCharsets()`, et
`req.acceptsLanguages()`. |
+| `res.location()` | No longer resolves relative URLs. |
+| `req.params` | Was an array; now an object. |
+| `res.locals` | Was a function; now an object. |
+| `res.headerSent` | Changed to `res.headersSent`. |
+| `app.route` | Now available as `app.mountpath`. |
+| `res.on('header')` | Removed. |
+| `res.charset` | Removed. |
+| `res.setHeader('Set-Cookie', val)` | La fonctionnalité est maintenant limitée à définir la valeur de base des cookies. Use `res.cookie()` for added functionality. |
## Exemple de migration d'applications
diff --git a/src/content/pages/fr/resources/utils.mdx b/src/content/pages/fr/resources/utils.mdx
new file mode 100644
index 0000000000..64f75c9be4
--- /dev/null
+++ b/src/content/pages/fr/resources/utils.mdx
@@ -0,0 +1,22 @@
+---
+title: Express utilities
+description: Discover utility modules related to Express.js and Node.js, including tools for cookies, CSRF protection, URL parsing, routing, and more to enhance your applications.
+---
+
+## Express utility functions
+
+The [pillarjs](https://github.com/pillarjs) GitHub organization contains a number of modules
+for utility functions that may be generally useful.
+
+| Utility modules | Libellé |
+| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [cookies](https://www.npmjs.com/package/cookies) | Get and set HTTP(S) cookies that can be signed to prevent tampering, using Keygrip. Can be used with the Node.js HTTP library or as Express middleware. |
+| [csrf](https://www.npmjs.com/package/csrf) | Contains the logic behind CSRF token creation and verification. Use this module to create custom CSRF middleware. |
+| [finalhandler](https://www.npmjs.com/package/finalhandler) | Function to invoke as the final step to respond to HTTP request. |
+| [parseurl](https://www.npmjs.com/package/parseurl) | Parse a URL with caching. |
+| [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) | Turn an Express-style path string such as \`\`/user/:name\` into a regular expression. |
+| [resolve-path](https://www.npmjs.com/package/resolve-path) | Resolves a relative path against a root path with validation. |
+| [router](https://www.npmjs.com/package/router) | Simple middleware-style router. |
+| [send](https://www.npmjs.com/package/send) | Library for streaming files as a HTTP response, with support for partial responses (ranges), conditional-GET negotiation, and granular events. |
+
+For additional low-level HTTP-related modules, see [jshttp](https://github.com/jshttp).
diff --git a/src/content/pages/fr/support.mdx b/src/content/pages/fr/support.mdx
new file mode 100644
index 0000000000..93c2d7bc52
--- /dev/null
+++ b/src/content/pages/fr/support.mdx
@@ -0,0 +1,23 @@
+---
+title: Support de la version
+description: Trouvez des informations sur le calendrier de support des différentes versions de Express.js, y compris les versions actuellement maintenues et les politiques de fin de vie.
+---
+
+Seule la dernière version d'une ligne de publication majeure est prise en charge.
+
+Les versions qui sont EdlV (fin de vie) _peuvent_ recevoir des mises à jour pour les vulnérabilités critiques de sécurité, mais l'équipe Express n'offre aucune garantie et ne prévoit pas de résoudre ou de corriger les problèmes rencontrés.
+
+| Version majeure | Version minimale de Node.js | Date de début du support | Date de fin du support |
+| -------------------------------------------------------------- | --------------------------- | ------------------------ | ---------------------- |
+| [**v5.x**](/5x/api) | 18 | Septembre 2024 | **en cours** |
+| [**v4.x**](/4x/api) | 0.10.0 | Avril 2014 | **en cours** |
+| [**v3.x**](/3x/api) | 0.8.0 | Octobre 2012 | Juillet 2015 |
+| [**v2.x**](https://github.com/expressjs/expressjs.com/tree/2x) | 0.4.1 | Mars 2011 | Juillet 2012 |
+| **v1.x** | 0.2.0 | Décembre 2010 | Mars 2011 |
+| **v0.14.x** | 0.1.98 | Décembre 2010 | Décembre 2010 |
+
+## Options de support commercial
+
+Si vous ne pouvez pas mettre à jour une version prise en charge de Express, veuillez contacter l'un de nos partenaires pour recevoir les mises à jour de sécurité :
+
+- [HeroDevs Never-Ending Support](https://www.herodevs.com/support/express-nes?utm_source=expressjs&utm_medium=link&utm_campaign=express_eol_page)
diff --git a/src/content/pages/it/advanced/best-practice-performance.mdx b/src/content/pages/it/advanced/best-practice-performance.mdx
new file mode 100644
index 0000000000..73c3264033
--- /dev/null
+++ b/src/content/pages/it/advanced/best-practice-performance.mdx
@@ -0,0 +1,333 @@
+---
+title: 'Production best practices: performance and reliability'
+description: Discover performance and reliability best practices for Express apps in production, covering code optimizations and environment setups for optimal performance.
+---
+
+This article discusses performance and reliability best practices for Express applications deployed to production.
+
+This topic clearly falls into the "devops" world, spanning both traditional development and operations. Accordingly, the information is divided into two parts: [things to do in your code](#things-to-do-in-your-code) (the dev part), and [things to do in your environment / setup](#things-to-do-in-your-environment--setup) (the ops part).
+
+## Things to do in your code
+
+Here are some things you can do in your code to improve your application's performance.
+
+### Use gzip compression
+
+Gzip compressing can greatly decrease the size of the response body and hence increase the speed of a web app. Use the [compression](https://www.npmjs.com/package/compression) middleware for gzip compression in your Express app. Per esempio:
+
+```cjs title="index.cjs"
+const compression = require('compression');
+const express = require('express');
+const app = express();
+
+app.use(compression());
+```
+
+```mjs title="index.mjs"
+import compression from 'compression';
+import express from 'express';
+
+const app = express();
+
+app.use(compression());
+```
+
+For a high-traffic website in production, the best way to put compression in place is to implement it at a reverse proxy level (see [Use a reverse proxy](#use-a-reverse-proxy)). In that case, you do not need to use compression middleware. For details on enabling gzip compression in Nginx, see [Module ngx_http_gzip_module](https://nginx.org/en/docs/http/ngx_http_gzip_module.html) in the Nginx documentation.
+
+### Don't use synchronous functions
+
+Synchronous functions and methods tie up the executing process until they return. A single call to a synchronous function might return in a few microseconds or milliseconds, however in high-traffic websites, these calls add up and reduce the performance of the app. Avoid their use in production.
+
+Although Node and many modules provide synchronous and asynchronous versions of their functions, always use the asynchronous version in production. The only time when a synchronous function can be justified is upon initial startup.
+
+You can use the `--trace-sync-io` command-line flag to print a warning and a stack trace whenever your application uses a synchronous API. Of course, you wouldn't want to use this in production, but rather to ensure that your code is ready for production. See the [node command-line options documentation](https://nodejs.org/api/cli.html#--trace-sync-io) for more information.
+
+### Do logging correctly
+
+In general, there are two reasons for logging from your app: For debugging and for logging app activity (essentially, everything else). Using `console.log()` or `console.error()` to print log messages to the terminal is common practice in development. But [these functions are synchronous](https://nodejs.org/api/console.html#console) when the destination is a terminal or a file, so they are not suitable for production, unless you pipe the output to another program.
+
+#### For debugging
+
+If you're logging for purposes of debugging, then instead of using `console.log()`, use a special debugging module like [debug](https://www.npmjs.com/package/debug). This module enables you to use the DEBUG environment variable to control what debug messages are sent to `console.error()`, if any. To keep your app purely asynchronous, you'd still want to pipe `console.error()` to another program. But then, you're not really going to debug in production, are you?
+
+#### For app activity
+
+If you're logging app activity (for example, tracking traffic or API calls), instead of using `console.log()`, use a logging library like [Pino](https://www.npmjs.com/package/pino), which is the fastest and most efficient option available.
+
+### Handle exceptions properly
+
+Node apps crash when they encounter an uncaught exception. Not handling exceptions and taking appropriate actions will make your Express app crash and go offline. If you follow the advice in [Ensure your app automatically restarts](#ensure-your-app-automatically-restarts) below, then your app will recover from a crash. Fortunately, Express apps typically have a short startup time. Nevertheless, you want to avoid crashing in the first place, and to do that, you need to handle exceptions properly.
+
+To ensure you handle all exceptions, use the following techniques:
+
+- [Use try-catch](#use-try-catch)
+- [Use promises](#use-promises)
+
+Before diving into these topics, you should have a basic understanding of Node/Express error handling: using error-first callbacks, and propagating errors in middleware. Node uses an "error-first callback" convention for returning errors from asynchronous functions, where the first parameter to the callback function is the error object, followed by result data in succeeding parameters. To indicate no error, pass null as the first parameter. The callback function must correspondingly follow the error-first callback convention to meaningfully handle the error. And in Express, the best practice is to use the next() function to propagate errors through the middleware chain.
+
+For more on the fundamentals of error handling, see:
+
+- [Error Handling in Node.js](https://web.archive.org/web/20210619211351/https://www.joyent.com/node-js/production/design/errors)
+
+#### Use try-catch
+
+Try-catch is a JavaScript language construct that you can use to catch exceptions in synchronous code. Use try-catch, for example, to handle JSON parsing errors as shown below.
+
+Here is an example of using try-catch to handle a potential process-crashing exception.
+This middleware function accepts a query field parameter named "params" that is a JSON object.
+
+```js
+app.get('/search', (req, res) => {
+ // Simulating async operation
+ setImmediate(() => {
+ const jsonStr = req.query.params;
+ try {
+ const jsonObj = JSON.parse(jsonStr);
+ res.send('Success');
+ } catch (e) {
+ res.status(400).send('Invalid JSON string');
+ }
+ });
+});
+```
+
+However, try-catch works only for synchronous code. Because the Node platform is primarily asynchronous (particularly in a production environment), try-catch won't catch a lot of exceptions.
+
+#### Use promises
+
+When an error is thrown in an `async` function or a rejected promise is awaited inside an `async` function, those errors will be passed to the error handler as if calling `next(err)`
+
+```js
+app.get('/', async (req, res, next) => {
+ const data = await userData(); // If this promise fails, it will automatically call `next(err)` to handle the error.
+
+ res.send(data);
+});
+
+app.use((err, req, res, next) => {
+ res.status(err.status ?? 500).send({ error: err.message });
+});
+```
+
+Also, you can use asynchronous functions for your middleware, and the router will handle errors if the promise fails, for example:
+
+```js
+app.use(async (req, res, next) => {
+ req.locals.user = await getUser(req);
+
+ next(); // This will be called if the promise does not throw an error.
+});
+```
+
+Best practice is to handle errors as close to the site as possible. So while this is now handled in the router, it’s best to catch the error in the middleware and handle it without relying on separate error-handling middleware.
+
+#### What not to do
+
+One thing you should _not_ do is to listen for the `uncaughtException` event, emitted when an exception bubbles all the way back to the event loop. Adding an event listener for `uncaughtException` will change the default behavior of the process that is encountering an exception; the process will continue to run despite the exception. This might sound like a good way of preventing your app from crashing, but continuing to run the app after an uncaught exception is a dangerous practice and is not recommended, because the state of the process becomes unreliable and unpredictable.
+
+Additionally, using `uncaughtException` is officially recognized as [crude](https://nodejs.org/api/process.html#event-uncaughtexception). So listening for `uncaughtException` is just a bad idea. This is why we recommend things like multiple processes and supervisors: crashing and restarting is often the most reliable way to recover from an error.
+
+We also don't recommend using [domains](https://nodejs.org/api/domain.html). It generally doesn't solve the problem and is a deprecated module.
+
+### Use worker threads for CPU-intensive tasks
+
+Node.js runs your JavaScript on a single thread, so a CPU-intensive operation (such as image processing, parsing or transforming large payloads, or cryptographic operations) can block the event loop and slow down every request your Express app is handling. If your app does CPU-bound work, you can run it in [worker threads](https://nodejs.org/api/worker_threads.html), which execute JavaScript in parallel within the same process, keeping the main thread free to serve requests.
+
+Each worker thread runs in its own JavaScript engine instance, so the data you pass to it through `workerData` or `postMessage` is copied, not shared. Copying large payloads has a cost of its own, which you can avoid by transferring objects such as `ArrayBuffer`s or by sharing memory explicitly with `SharedArrayBuffer`. Worker threads are not a replacement for [running your app in a cluster](#run-your-app-in-a-cluster), which scales your app across CPU cores by running multiple instances of it in separate processes.
+
+This example offloads an image-resizing task to a worker, where `resize-worker.js` receives the image via `workerData` and posts the result back when it's done:
+
+```js
+const { Worker } = require('node:worker_threads');
+
+app.post('/resize', (req, res, next) => {
+ const worker = new Worker('./resize-worker.js', { workerData: req.body.image });
+
+ worker.once('message', (result) => res.send(result));
+ worker.once('error', next);
+});
+```
+
+Note that this example is kept simple for illustration: creating a worker thread is relatively expensive, so [the Node.js documentation recommends using a pool of workers](https://nodejs.org/api/worker_threads.html#worker-threads) instead of spawning a new one for every request. Create a fixed pool of workers at startup and dispatch tasks to them as requests come in, for example with a library like [piscina](https://www.npmjs.com/package/piscina):
+
+```js
+const path = require('node:path');
+const Piscina = require('piscina');
+
+const pool = new Piscina({ filename: path.resolve(__dirname, 'resize-worker.js') });
+
+app.post('/resize', async (req, res, next) => {
+ try {
+ res.send(await pool.run(req.body.image));
+ } catch (err) {
+ next(err);
+ }
+});
+```
+
+Here `resize-worker.js` simply exports the function to run in the pool, and piscina takes care of creating the workers, queueing tasks, and reusing threads across requests.
+
+For more guidance on keeping the event loop responsive, including when offloading work is worth its communication costs, see [Don't Block the Event Loop](https://nodejs.org/learn/asynchronous-work/dont-block-the-event-loop) in the Node.js documentation.
+
+## Things to do in your environment / setup
+
+Here are some things you can do in your system environment to improve your app's performance.
+
+### Set NODE_ENV to "production"
+
+The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production). One of the simplest things you can do to improve performance is to set NODE_ENV to `production`.
+
+Setting NODE_ENV to "production" makes Express:
+
+- Cache view templates.
+- Cache CSS files generated from CSS extensions.
+- Generate less verbose error messages.
+
+[Tests indicate](https://web.archive.org/web/20250814011110/https://www.dynatrace.com/news/blog/the-drastic-effects-of-omitting-node-env-in-your-express-js-applications/) that just doing this can improve app performance by a factor of three!
+
+If you need to write environment-specific code, you can check the value of NODE_ENV with `process.env.NODE_ENV`. Be aware that checking the value of any environment variable incurs a performance penalty, and so should be done sparingly.
+
+In development, you typically set environment variables in your interactive shell, for example by using `export` or your `.bash_profile` file. But in general, you shouldn't do that on a production server; instead, use your OS's init system (systemd). The next section provides more details about using your init system in general, but setting `NODE_ENV` is so important for performance (and easy to do), that it's highlighted here.
+
+With systemd, use the `Environment` directive in your unit file. Per esempio:
+
+```sh
+
+Environment=NODE_ENV=production
+```
+
+For more information, see [Using Environment Variables In systemd Units](https://www.flatcar.org/docs/latest/setup/systemd/environment-variables/).
+
+### Use the latest LTS version of Node.js
+
+Running your app on a recent Node.js release is one of the easiest ways to improve performance. Each new version of Node.js ships with cumulative improvements to the V8 JavaScript engine and the runtime itself, so the same Express app can handle significantly more requests simply by upgrading. Benchmarks such as NodeSource's [Node.js Performance Report](https://nodesource.com/pages/content-node-performance-report-wb.html) show how much throughput can improve from one Node.js version to the next. For production, use the latest [LTS release](https://nodejs.org/en/about/previous-releases) of Node.js, and keep it up to date as new versions come out.
+
+### Ensure your app automatically restarts
+
+In production, you don't want your application to be offline, ever. This means you need to make sure it restarts both if the app crashes and if the server itself crashes. Although you hope that neither of those events occurs, realistically you must account for both eventualities by:
+
+- Using a process manager to restart the app (and Node) when it crashes.
+- Using the init system provided by your OS to restart the process manager when the OS crashes. It's also possible to use the init system without a process manager.
+
+Node applications crash if they encounter an uncaught exception. The foremost thing you need to do is to ensure your app is well-tested and handles all exceptions (see [handle exceptions properly](#handle-exceptions-properly) for details). But as a fail-safe, put a mechanism in place to ensure that if and when your app crashes, it will automatically restart.
+
+#### Use a process manager
+
+In development, you started your app simply from the command line with `node server.js` or something similar. But doing this in production is a recipe for disaster. If the app crashes, it will be offline until you restart it. To ensure your app restarts if it crashes, use a process manager. A process manager is a "container" for applications that facilitates deployment, provides high availability, and enables you to manage the application at runtime.
+
+In addition to restarting your app when it crashes, a process manager can enable you to:
+
+- Gain insights into runtime performance and resource consumption.
+- Modify settings dynamically to improve performance.
+- Control clustering (pm2).
+
+Historically, it was popular to use a Node.js process manager like [PM2](https://github.com/Unitech/pm2). See their documentation if you wish to do this. However, we recommend using your init system for process management.
+
+#### Use an init system
+
+The next layer of reliability is to ensure that your app restarts when the server restarts. Systems can still go down for a variety of reasons. To ensure that your app restarts if the server crashes, use the init system built into your OS. The main init system in use today is [systemd](https://wiki.debian.org/systemd).
+
+There are two ways to use init systems with your Express app:
+
+- Run your app in a process manager, and install the process manager as a service with the init system. The process manager will restart your app when the app crashes, and the init system will restart the process manager when the OS restarts. This is the recommended approach.
+- Run your app (and Node) directly with the init system. This is somewhat simpler, but you don't get the additional advantages of using a process manager.
+
+##### Systemd
+
+Systemd is a Linux system and service manager. Most major Linux distributions have adopted systemd as their default init system.
+
+A systemd service configuration file is called a _unit file_, with a filename ending in `.service`. Here's an example unit file to manage a Node app directly. Replace the values enclosed in `\