title: How to create MySQL database connection in Coffeescript
body: <p>How to connect MySQL database in CoffeeScript. How to run this.I created MySQL connection using node.js and display record in terminal but how to display this on browser.I am using ECO templating for displaying on browser. I need database connection using coffeescript</p>
  
  <p><strong>file - db_test.js</strong></p>
  
  <pre><code>  var mysql = require("mysql");
    var con = mysql.createConnection({
      host: "localhost",
      user: "root",
      password: "",
      database: "test"
  });
  
    con.connect(function(err){
      if(err){
         console.log('Error connecting to Db');
         return;
      }
      console.log('Connection established');
  });
  
   con.query('SELECT * FROM users',function(err,rows){
        if(err) throw err;
        for (var i = 0; i &lt; rows.length; i++) {
         console.log(rows[i].username);
      };
  });
  
  con.end(function(err) {
    // The connection is terminated gracefully
    // Ensures all previously enqueued queries are still
    // before sending a COM_QUIT packet to the MySQL server.
  });
  </code></pre>