req.body in get request code example
Example 1: How to access the request body when POSTing using Node.js and Express
const express = require('express');
const app = express();
app.use(express.json({extended: false}));
app.post('/postroute', (req, res) => {
console.log('body :', req.body);
res.sendStatus(200);
});
Example 2: how to access the req.body
const express = require('express')
const app = express()
app.use(
express.urlencoded({
extended: true
})
)
app.use(express.json())
Example 3: req.body
(req.body, ' ' , ' ') --> here req is the parameter of your function and using this parameter your can access the properties over then url.
so look this example
suppose this is form
<form>
enter the name : <input type="text" name="name">
<button type ="submit"> submit </button>
</form>
so if you want to access the name -- which is filled by the user end.
so for this you can
do like this-> console.log(req.body.name); -- this will print the name (property) in console.