I am very new to node js. I am just testing some stuff about client-server communication.
I have these codes:
server:
app.post('/zsa', (req, res) => {
res.send("zsamo");
});
client:
fetch("http://localhost:3000/zsa", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((data) => {
console.log(data);
});
With this code i get a response object:
I want to log to the console what was in the response data: "zsamo"
2
Answers
fetch
returns a Response. If you want JSON from the body of your response then you can do this:See also Using the Fetch API
At client side, in console.log instead of data, write data.body