Define application routes
Build an HTTP server with route handlers.
Express.js · Interface
The Express application object is created with express() and conventionally stored in app. It registers middleware and HTTP-method routes and can handle incoming requests.
Calling the top-level express() function creates an application object. The returned app can register middleware and HTTP-method routes, then listen for incoming connections; it is also available as req.app and res.app during request handling.
const app = express();| Name | Type | Description |
|---|---|---|
| | No parameters are documented for the application interface itself; individual application methods define their own arguments. |
The express() function returns an Express application instance.
app and represents the Express application.express() to create the application instance.req.app or res.app.get, post, and put.app.all() only when middleware should run for every HTTP method at the selected path; it is not an ordinary HTTP-method route.app.get() and app.post() when defining routes.import express from "express";
const app = express();
app.get("/", (_req, res) => {
res.send("Hello World!");
});
app.listen(3000);Creates an Express application, registers a GET route, and starts listening on port 3000.
Build an HTTP server with route handlers.
Apply shared processing such as authentication or parsing.
Expose the app to the Node.js HTTP server.
Access application configuration from handlers.
express()app.all()app.METHOD()app.get()app.post()app.put()app.delete()app.use()