alright, i figured that out.
the whole problem is with the html input. not with the parser configurations.
the problem is that when you are sending something via postman for example,
if you wanna send application/x-www-form-urlencoded type, postman will give you a interface for you to set a key value pair. if yo usend a raw json tahts the same thing as "application/json" i think, you will have to set a valid json, with key value pairs.
on postman, if you send either without providing a key to the value, the req.body will result being empty, as express says in the docs
"A new body object containing the parsed data is populated on the
request object after the middleware (i.e. req.body), or an empty
object ({}) if there was no body to parse, the Content-Type was not
matched, or an error occurred."
i never understood the reason of "name" attribute on html inputs and stuff. well, i humbly think that this is the value (i havent searched yet).
the solution was to set a name attribute on the input =>
the response of the body was => name:'... whatever was passed on the input ...'
code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="/" , method="POST">
<!-- <input type="text" id="name" name="name" placeholder="name" required> -->
<input type="text" name="name"> // name attribute is the key "name" for your input.
<input type="text" name="age"> // name attribute is the key "age" for your attribute.
<input type="submit">
</form>
</body>
</html>
javascript:
const express = require('express')
const path = require('path')
const app = express()
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.get('/', (req, res) => {
res.sendFile('index.html', { root: path.join(__dirname) })
})
app.post('/', (req, res) => {
console.log(req.body) // the result is the input value.
})
app.listen(3000, () => {
console.log('working')
})