Junior — Middle
What components are included in the structure of the Express.js framework?
sobes.tech AI
Answer from AI
Express.js is a minimal and flexible web framework for Node.js. Its structure includes several key components:
- Middleware — functions that handle requests and responses, can modify request/response objects, end the processing cycle, or pass control further.
- Router — a component for defining routes (URL paths) and linking them to handlers.
- Request and Response objects — wrappers around the HTTP request and response, providing convenient methods and properties.
- Application object (app) — the main Express object that manages settings, middleware, and routes.
Example of creating a simple application:
const express = require('express');
const app = express();
// Middleware
app.use(express.json());
// Route
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000);