Developing a web application using the node.js framework we can easily write code that connects with a MySQL database. The mysql module provides us with everything we need. The following code sample shows how simple it is to use this module.

var mysql = require('mysql');
var connection = mysql.createConnection({
host: '',
user: 'nodejsdemo',
password: 'lifemichael',
database: 'nodejsdemo',
port: 3306 });
var query = connection.query('SELECT * FROM products',
	function(err, result, fields) 
		if (err) throw err;
		console.log('result: ', result);

The following video clip overviews this code sample, shows its execution and explains it.

You can find more video clips, code samples and various other training material for learning how to use node.js in my free online courses website at

Leave a Reply

Your email address will not be published. Required fields are marked *