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.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Receiving Data from Client
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.
Thanks for your feedback!