Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Request and Response Basics | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Building APIs with Express.js

bookRequest 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.

question mark

Which object is used to send data back to the client?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 5

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 1. Chapter 5
some-alt