Querying MySQL with Node.js [team]

posted in: NodeJS, SQL | 0
/**
 * Created by Andre on 2015/01/08.
 * Use this approach to add Setup and Teardown to FrisbyJS
 */
var mysql = require('mysql');

var connection = mysql.createConnection(
    {
        host     : 'localhost',
        user     : 'root',
        password : '',
        database : 'cleverdb'
    }
);

connection.connect();

var queryString = 'SELECT * FROM Users';

connection.query(queryString, function(err, rows, fields) {
    if (err) throw err;

    for (var i in rows) {
        console.log('Users list: ', rows[i].email);
    }
});

connection.end();

Leave a Reply