Home > Back-end >  Nodejs http server json parse
Nodejs http server json parse

Time:12-20

why the parameter data different in console and website

i need use JSON.stringify or JSON.parse in res.end?

CodePudding user response:

The JSON.stringify() method converts a JavaScript object or value to a JSON string, so add this to your res.end()

res.end(JSON.stringify(data));

CodePudding user response:

I think this code will help you.

res.end(data.toString())

I'll explain the reason why it is different in console and website. In console, the data is type of buffer, so it can probably output data in byte format. But in the web browser, the data is parsed in JSON string, so it'll be converted to string and correct result comes out.

  • Related