title: How can I pass mysql result in object using node js?
body: <p>Can anyone knows how can I pass MySQL result to a JSON object using NodeJS?</p>
  
  <pre><code>// my code
  var mysql = require('mysql');
  var records = {};
  
  var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: ''
  });
  
  connection.query('USE MyDB');
  
  function getRecords() {
    connection.query("select * from records where id = ?", id, function(err, result) {
      if (err) {
          return done(err);
      }
  
      records = result;
      return records;
    });
  }
  </code></pre>
  
  <p>From these code, I want to use the return records in other operations in my project. Can anyone help me to pass MySQL result to JSON object so I can use the data outside the function?</p>
  
  <p>Thank you.</p>