title: Nodejs how convert the rows of postgresql query result to json array?
body: <p>I get below query result from postgreSQL data base, then I want to send the response which should <strong>only</strong> has part: <strong>rows</strong> to the client. I need the response is in json format, so could you please tell how can I convert the query result: <strong>rows</strong> into json array?</p>
  
  <pre><code>Result {
        command: 'SELECT',
        rowCount: 1,
        oid: NaN,
        rows:
         [ anonymous {
             uid: 23,
             name: 'Test Human',
             email: 'test@example.com',
             password: 'test',
             created: 2018-08-24T09:44:19.659Z,
             terminited: null } 
           anonymous {
             uid: 12,
             name: 'Test Animal',
             email: 'ani@example.com',
             password: 'hello',
             created: 2018-08-24T09:44:19.659Z,
             terminited: null }
        ],
        fields:
         ...
         _parsers:
         [ [Function: parseInteger],
           [Function: noParse],
           [Function: noParse],
           [Function: noParse],
           [Function: parseDate],
           [Function: parseDate] ],
        RowCtor: [Function: anonymous],
        rowAsArray: false,
        _getTypeParser: [Function: bound ] }
  </code></pre>
  
  <p>Node.js code:</p>
  
  <pre><code>// router for get friends  information
  router.get("/getfriends", (req, res) =&gt; {
  
     const uid = req.query.uid;
     pool.connect((err, client, done) =&gt; {
      if (err) throw err;
      const fetchRow = async() =&gt;{
         await client.query('SELECT * FROM friends where follower = $1 ORDER by id ASC', [uid], (err, result) =&gt; {
           done()
           if(err){
             console.log(err.stack)
             res.status(400).json(err)
           } else {
             /*here I want to response rows only with JSON format, but result.rows doesn't realise that...*/
             console.log(result.rows)
             res.status(200).json(result.rows)
          }
        })
      }
      fetchRow()
     })
  })
  </code></pre>