Express.js- add response body

后端 未结 2 1715
孤街浪徒
孤街浪徒 2021-02-14 17:43

I would like to add a body property to Express.js\' response object, which will be called every time the send method is called, I do it by adding the f

2条回答
  •  滥情空心
    2021-02-14 18:18

    You are probably using something like this:

    res.send({ foo : 'bar' });
    

    In other words, you're passing an object to res.send.

    This will do the following:

    • call res.send with the object as argument
    • res.send checks the argument type and sees that it's an object, which it passed to res.json
    • res.json converts the object to a JSON string, and calls res.send again, but this time with the JSON string as argument

提交回复
热议问题