Unable to send numbers using res.send() using express with node

前端 未结 3 725
鱼传尺愫
鱼传尺愫 2020-12-19 03:31

I am trying to get the \"imdb rating\" using express in node and I am struggling.

movies.json

[{
\"id\": \"3962210\",
\"order\": [4.         


        
3条回答
  •  情书的邮戳
    2020-12-19 04:20

    According to Express res.send([body]) docs:

    The body parameter can be a Buffer object, a String, an object, or an Array

    You can't send a number by itself.

    Try either converting the number to a string

    res.send(''+result.rows[0].doc.imdb.rating);
    

    or send it as an object value

    res.send({ result: result.rows[0].doc.imdb.rating});
    

提交回复
热议问题