I am fetching data from my backend using fetch function and it returns a readableStream as response’s body. How can I extract the data in that readable stream?
I’ve tries using res.json
method, but it returns undefined.
Here’s my fetch call –
fetch('/playground',{
method: 'POST',
}).then(function(res){
res.json()
}).then(data => console.log(data))
it returns undefined
in the console.
Here’s the code from node.js server
router.route('/playground')
.post((req,res)=>{
res.send({message: 'Hello from backend'})
})
I was expecting it to give me output as an object with key value pair as
{
message: "Hello from backend"
}
but it returns undefined