Request and Response Basics
Swipe to show menu
Every route in Express works with two objects: the request and the response.
The req object contains information about the incoming request.
The res object is used to send a response back to the client.
const express = require('express');
const app = express();
app.get('/', (req, res) => {
console.log(req.method);
res.send('Hello');
});
app.listen(3000);
The request object can provide useful details about the request:
- Request Method:
req.method; - Request URL:
req.url.
The response object is used to send data back:
res.send('Hello');
Once a response is sent, the request is completed.
Understanding these two objects is essential because every backend action starts with a request and ends with a response.
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 5
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Section 1. Chapter 5