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

bookReceiving Data from Client

Swipe to show menu

When a client sends data to the server, it is usually included in the request body.

To read this data in Express, you need to enable JSON parsing using middleware:

app.use(express.json());

After that, you can access incoming data using req.body.

app.post('/users', (req, res) => {
  const user = req.body;

  res.json(user);
});

If a client sends:

{ "name": "John", "age": 25 }

You can access it like this:

  • Name: req.body.name;
  • Age: req.body.age.

This is commonly used when creating or updating data in backend applications.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 9

Ask AI

expand

Ask AI

ChatGPT

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

Section 1. Chapter 9
some-alt