{"id":18037,"library":"expresss","title":"Express.js","description":"Express.js is a foundational, unopinionated web application framework for Node.js, widely regarded as the de facto standard for building web applications and APIs. It provides a robust yet minimalist set of features, including a powerful routing system, HTTP utility methods, and a flexible middleware architecture. The current stable major version is Express 5.x, with Express 5.1.0 being the default on npm, and an official LTS schedule supports both v4 and v5 release lines. The release cadence for major versions can be extended, as seen with the significant time between Express 4 and Express 5, which focused on improving core stability, aligning with modern Node.js features, and incorporating security enhancements rather than introducing a vast array of new features. Its key differentiators include its lightweight nature, high extensibility through a vast ecosystem of middleware, and its \"unopinionated\" approach, allowing developers significant freedom in structuring their applications and choosing components like ORMs and template engines. It is often a core component of the \"MEAN\" or \"MERN\" stack for full-stack JavaScript development. Note: The package 'expresss' is a likely typo; this entry refers to the correct package 'express'.","status":"active","version":"0.0.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install expresss","lang":"bash","label":"npm"},{"cmd":"yarn add expresss","lang":"bash","label":"yarn"},{"cmd":"pnpm add expresss","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import style, requires 'type': 'module' in package.json or a .mjs file extension. Node.js 18+ is recommended for modern ESM usage with Express 5.","wrong":"const express = require('express');","symbol":"express","correct":"import express from 'express';"},{"note":"CommonJS (CJS) require style, the traditional way to import Express in Node.js applications. This is the default in Node.js unless explicitly configured for ESM.","wrong":"import express from 'express';","symbol":"express","correct":"const express = require('express');"},{"note":"While `express` itself is a default export, you can specifically import `Router` for modular route handling without creating a full application instance. However, typically `express.Router()` is used.","wrong":"import Router from 'express/lib/router';","symbol":"Router","correct":"import { Router } from 'express';"}],"quickstart":{"code":"import express from 'express';\n\nconst app = express();\nconst port = process.env.PORT ?? 3000;\n\napp.get('/', (req, res) => {\n  res.send('Hello from Express.js!');\n});\n\napp.get('/api/data', (req, res) => {\n  res.json({ message: 'This is some API data!', timestamp: new Date() });\n});\n\napp.listen(port, () => {\n  console.log(`Express app listening on port ${port}`);\n  console.log(`Access at http://localhost:${port}`);\n});","lang":"typescript","description":"This quickstart sets up a basic Express.js server with two routes: a root path returning 'Hello World!' and an API endpoint returning JSON data. It demonstrates server initialization and route handling. Ensure 'type': 'module' in package.json for ESM imports or use require()."},"warnings":[{"fix":"Upgrade Node.js to version 18 or later. Use `nvm` or your preferred Node.js version manager for easy switching: `nvm install 18 && nvm use 18`.","message":"Express 5.x requires Node.js version 18 or higher. Applications running on older Node.js versions must be upgraded before migrating to Express 5.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use `app.delete()` instead of `app.del()`. For response methods, chain `res.status(statusCode).send(body)` or `res.sendStatus(statusCode)`. Replace `res.redirect('back')` with `res.redirect(req.get('Referrer') || '/')`. Consult the official migration guide for specific replacements.","message":"Several deprecated method signatures from Express 4 have been removed in Express 5, including `app.del()`, `res.send(status, body)`, `res.send(status)`, `res.redirect('back')`, and `res.json(obj, status)`.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review and update all route path definitions to conform to the new stricter syntax. Use named wildcards like `/*splat` for wildcard matches. Refer to the 'Migrating to Express 5' documentation for detailed examples.","message":"The path route matching syntax has stricter rules in Express 5, particularly concerning named wildcards (`*`) and regular expressions. For instance, `/*` should now be `/*splat`.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Ensure `express.json()` and `express.urlencoded({ extended: true })` (if needed) middleware are explicitly added to your application. Access `req.body` only after these middleware have processed the request.","message":"Body parsing behavior has changed in Express 5. `req.body` is no longer initialized to an empty object by default, and the `urlencoded` middleware's `extended` option now defaults to `false`. The standalone `bodyParser()` middleware is also removed.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review your asynchronous route handlers and middleware. Remove redundant `try/catch` blocks that just call `next(err)`, as Express 5 now handles this automatically. Ensure your main error-handling middleware is correctly set up to catch these forwarded errors.","message":"In Express 5, rejected promises returned from asynchronous middleware and route handlers are now automatically caught and forwarded to the error-handling middleware. This simplifies async error handling but might alter behavior for applications that previously handled rejections manually.","severity":"gotcha","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Replace `app.del('/path', handler)` with `app.delete('/path', handler)`.","cause":"Attempting to use the deprecated `app.del()` method in Express 5.","error":"TypeError: app.del is not a function"},{"fix":"Add `app.use(express.json());` and/or `app.use(express.urlencoded({ extended: true }));` (if parsing URL-encoded data) before your routes that access `req.body`.","cause":"The body parsing middleware (`express.json()` or `express.urlencoded()`) is missing or incorrectly applied, especially in Express 5 where `req.body` is not initialized by default.","error":"TypeError: Cannot read properties of undefined (reading 'body') or req.body is undefined"},{"fix":"Ensure consistency in your module system. If using ES Modules (with `\"type\": \"module\"` in `package.json` or `.mjs` files), use `import` statements. If sticking to CommonJS, use `require()`. For specific cases needing both, consider dynamic `import()` or `createRequire` in Node.js.","cause":"Mixing CommonJS `require()` syntax with ES Modules `import` syntax without proper configuration, or attempting to use `require()` in a file treated as an ESM module.","error":"ERR_REQUIRE_ESM or TypeError: require is not a function (when using import)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}