title: How to wait until mysql query is done and then continue to run the script?
body: <p>I've made a class in which the constructor is being declared mostly by a mySQL query that looks like that:</p>
  
  <pre><code>constructor(username) {
  
  
          this.mysql = require('mysql');
  
  // create a connection variable with the required details
          this.con = this.mysql.createConnection({
              host: "localhost", // ip address of server running mysql
              user: "root", // user name to your mysql database
              password: "", // corresponding password
              database: "db" // use the specified database
          });
  
          this.username = username;
          this._password = "";
          this.con.query("SELECT * FROM users WHERE username = ?", this.username, function (err, result, fields) {
              if (err) throw err;
              this._password = result[0].password;
          });
      }
  
  get password() {
          return this._password;
      }
  </code></pre>
  
  <p>The issue is , when I'm declaring the class like that:</p>
  
  <pre><code>const user= require("./user.js");
  let bot = new user("user1");
  console.log(user.password();
  </code></pre>
  
  <p>The code first accessing the get and getting undefined , and only after the the query is done.</p>
  
  <p>How can I fix it?</p>