Express.js is a minimalist, unopinionated, and flexible Node.js web application framework, designed for building robust APIs and web applications. It provides a thin layer of fundamental web application features atop Node.js's built-in HTTP module, emphasizing speed and extensibility through its middleware-centric architecture. The current stable release is v5.2.1, with the v5 branch representing a major overhaul focused on simplifying the codebase and improving security. The v4.x branch (currently v4.22.1) is also actively maintained, primarily for security patches and critical bug fixes, serving projects that haven't yet migrated to v5. Its unopinionated nature contrasts with more prescriptive frameworks, offering maximum flexibility in project structure and choice of components, allowing developers to easily extend functionality for tasks like routing, parsing request bodies, handling sessions, and serving static files.
npm install alemmiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic Express.js server using TypeScript and ES modules. It includes JSON body parsing middleware, a custom logging middleware, a GET route, a POST route handling JSON data, and a fundamental error handler, showcasing a typical setup for an Express application.
Review the official Express v5 release blog post (expressjs.com/2024/10/15/v5-release.html) and migration guides to understand specific changes and ensure your Node.js environment meets the new requirements before upgrading.
Upgrade immediately to `5.2.1` or `4.22.1` (or newer) to avoid the unintended query parser behavior introduced in the prior patch. No security vulnerability was ultimately confirmed for this specific issue.
Upgrade to Express `5.0.1` or `4.21.1` (or newer) to incorporate the security fix for `CVE-2024-47764` and ensure proper cookie handling.
Replace `res.redirect('back')` with a specific URL or implement custom logic to determine the previous URL from request headers (e.g., `req.get('Referrer')`) for explicit and predictable redirects.Always define global or route-specific middleware functions before the route handlers they are intended to process. Ensure error-handling middleware is defined last in the middleware chain.
Wrap `async` route handlers and middleware in a `try...catch` block and call `next(error)` in the catch block to pass errors to the Express error handler. Alternatively, use a package like `express-async-errors` to automatically wrap and handle promise rejections.
Ensure the argument passed to `app.use()` or `router.use()` is a valid function (e.g., `express.json()`, `myCustomMiddleware`) or an array of middleware functions.
Define a route handler using `app.get()`, `app.post()`, `app.put()`, etc., for the specific path and method. If serving static files, ensure `express.static()` middleware is correctly configured and placed before other routes.
For `async` middleware/routes, wrap the code in a `try...catch` block and call `next(error)` in the catch. Alternatively, use a dedicated library like `express-async-errors` to automatically catch promise rejections and pass them to your error handlers.
No dependency data recorded yet.