Responding with a JSON object in Node.js (converting object/array to JSON string)

前端 未结 6 1088
广开言路
广开言路 2020-12-04 08:01

I\'m a newb to back-end code and I\'m trying to create a function that will respond to me a JSON string. I currently have this from an example

function rando         


        
6条回答
  •  遥遥无期
    2020-12-04 08:35

    Per JamieL's answer to another post:

    Since Express.js 3x the response object has a json() method which sets all the headers correctly for you.

    Example:

    res.json({"foo": "bar"});
    

提交回复
热议问题