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: 'server.zindell.com',
user: 'nodejsdemo',
password: 'lifemichael',
database: 'nodejsdemo',
port: 3306 });
connection.connect();
var query = connection.query('SELECT * FROM products',
	function(err, result, fields) 
	{
		if (err) throw err;
		console.log('result: ', result);
	});
connection.end();

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 http://abelski.lifemichael.com.

Leave a Reply

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