In node, "req.body" is used to obtain the data in the request; since parsing body is not provided by nodejs by default, this method needs to load the "body-parser" middleware before it can be used, and This method is usually used to parse the data of POST requests, and the syntax is "req.body.name".
The operating environment of this tutorial: windows10 system, nodejs version 12.19.0, Dell G3 computer.
Getting the parameters in the request is the only way for every web background processing. The express framework of nodejs provides four methods to achieve it. .
1,req.body
2,req.query
3,req.params
4,req.param()
req.body
A little translation: The key-value pair containing the submitted data is in the body of the request. The default is underfined.
You can use body- parser or multer to parse body
Parsing body is not provided by nodejs by default. You need to load the body-parser middleware before you can use req.body;
This method is usually used Parse the data in the POST request
req.body is used in the post request
The usage is as follows
Recommended learning: "nodejs video tutorial"
The above is the detailed content of What is the usage of req.body in node. For more information, please follow other related articles on the PHP Chinese website!