How to Read POST Request Body - Node.js Tutorial 9

preview_player
Показать описание


~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

Рекомендации по теме
Комментарии
Автор

thanks bro, I spent the past hour wondering why am undefined request body

ahmedyousif
Автор

Thanks for the video. Was racking my brain as to why it wasn't working even though my syntax was right. It was something as simple as checking the data-type in the postman request to "JSON".

katabolik-dev
Автор

love your openess, thanks . i was doing some extensive reading on getting json and this was nice

manuelfash
Автор

do we have to use the body-parser package?

eudeamonism
Автор

why doesnt this work? it says 'cannot get api/test'

NotSar
Автор

What app do you use to send post requests?

francescocaccavale
Автор

hello!

i am trying to get node to read the body of my request, but it returns an empty object



server
app.use(express.json())


app.post('/db', (req, res)=>{

console.log(req.body)
res.send(req.body)
})

client

var uri = '/db'
var obj = {hi:"hello"}
var js = true

function poster(data = obj){
fetch(uri,
{
method:'POST',
headers:{ 'Content-Type': 'application/json'},


body:JSON.stringify(data)
}).then((res)=>{

console.log('post res', res)
if(res.ok){
if(!js){
res.text().then(t=>{
console.log('text', t)
document.body.append(t)
})
}else{
res.json().then(j=>{
console.log(j)
})}
}else{
console.log('res not okay', res)
}
})
}

do you know why is that happening?

Felipekimst
welcome to shbcf.ru