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

前端 未结 3 713
鱼传尺愫
鱼传尺愫 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 03:58

    this works, you have to convert it to a string: threeFunction().toString() or x1.toString()

    0 讨论(0)
  • 2020-12-19 04:15

    Integer is not valid for res.send() so convert it to string.

    res.send(value.toString())
    
    0 讨论(0)
  • 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});
    
    0 讨论(0)
提交回复
热议问题