title: Save an SQL object to a file using Node.js
body: <p>I need to save the object <code>rows</code> in a file or save it to a JSON file.</p>
  <pre class="lang-js prettyprint-override"><code>app.get('/getposts', (req, res) =&gt; {
    mysqlConnection.query('Select * from posts', (err, rows, fields) =&gt; {
      if (!err) console.log(rows);
      else
        console.log(err);
  
      res.send(rows);
  </code></pre>