title: How to close database connection in node.js?
body: <p>When i am closing database connection in <strong>node.js</strong> i am getting this error</p>
  
  <p><code>Cannot enqueue Query after invoking quit</code>.</p>
  
  <p>Here is my <strong>code</strong></p>
  
  <pre><code>socket.on('adminConnect', function (email) {
      connection = mysql.createConnection(db_config); // db_config has all details of database
      connection.connect(); // no problem in connection
      connection.query("SELECT id FROM user WHERE  email = '" + email + "' ", function (err, results, fields) {
          if (err) throw err;
          if (results[0]) {
              // Some code
              connection.end(); // its giving error "Cannot enqueue Query after invoking quit."
          } else {
              console.log("no id");
          }
      });
  });
  </code></pre>