Receiving 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?
Thanks for your feedback!
Section 1. Chapter 9
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Section 1. Chapter 9