0
Why i am getting the error: unexpected token h in JSON at position 0? [Solved]
So i am making request to this server and getting data from it using the following code but I get the above mentioned error ,so can anybody tell me why is it so and how can I solve it ,also using res.text() works fine,thank you in advance! const fet=require("node-fetch"); fet('http://localhost:9000/') .then(res=>res.json()) .then(body=>console.log(body)); https://code.sololearn.com/c7leBCM7fiHI/?ref=app
3 odpowiedzi
+ 3
because "hello" is not in JSON format
maybe it should look like this
{"mesage":"hello"}
+ 1
change the res.write to json instread of plain string
JSON.stringify({message:"hello"})
or
'{"mesage":"hello"}'
0
Taste so can you pls tell what changes I need to make in both of the codes ?