Node JS - Node js mysql - Node - Node JS tutorial - webnode

What is Node.js MySQL ?

  • Node.js can be used in database applications.
  • One of the most popular databases is MySQL.
  • This is a node.js driver for mysql. It is written in JavaScript, does not require compiling.
  • It provides all most all connection/query from MySQL. 
  • learn nodejs - node-js tutorial - node js restful api mysql - nodejs examples -  nodejs programs
  • Node-mysql is probably one of the best modules used for working with MySQL database and the module is actively maintained.
 node-js mysql

Learn Node js - node js Tutorial - node.js mysql - node - Node js Examples

Why use node.js with DB?

  • Multiple data updates to a database can create chaos in normal synchronized processes.
  • node.js manages these simultaneous connections via message queues.
  • This approach is generally useful when there are concurrent batch uploads to database, that are collected for use in later stage.
  • Eg. User Log are collected and uploaded to database which are used later for report preparations. Such data uploads don’t require immediate acknowledgements and hence they are handled by node.js event driven queues.

MySQL Database:

  • To be able experiment with the code examples, you should have MySQL installed on your computer.
  • You can download a free MySQL database at

Install MySQL Driver:

  • Once you have MySQL up and running on your computer, you can access it by using Node.js.
  • To access a MySQL database with Node.js, you need a MySQL driver.
  • This tutorial will use the "mysql" module, downloaded from NPM.
  • To download and install the "mysql" module, open the Command Terminal and execute the following:
C:\Users\Your Name>npm install mysql
  • Now you have downloaded and installed a mysql database driver.
  • Node.js can use this module to manipulate the MySQL database:
var mysql = require('mysql');

Create Connection:

  • Start by creating a connection to the database.
  • Use the username and password from your MySQL database.


var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "wikitechy",
  password: "venkat_wikitechy"

con.connect(function(err) {
  if (err) throw err;


  • Save the code above in a file called "demo_db_connection.js" and run the Node JS Tutorial File:
Run "demo_db_connection.js"
C:\Users\Your Name>node demo_db_connection.js


  • Now you can start querying the database using SQL statements.

Query a Database:

  • Use SQL statements to read from (or write to) a MySQL database. This is also called "to query" the database.
  • The connection object created in the example above, has a method for querying the database:
con.connect(function(err) {
  if (err) throw err;
  con.query(sql, function (err, result) {
    if (err) throw err;
    console.log("Result: " + result);

This wikitechy technological portal provides you whole lot of information related to the topics such as mongodb tutorial , what is node js , express js tutorial , node js tutorial pdf , learn node js , node js tutorial for beginners , node js tutorial w3schools , node js express , javascript for beginners , node js express tutorial , node js tutorial point , node js book , node js server , note js , node js mongodb , what is node js used for , why node js , node tutorial , node js basics , tutorialspoint node js , node express , node js sample application , nodeschool , node js for beginners , express tutorial , node js application , use of node js , npm tutorial , node js org , node js training , node js online training , node js tutorial beginner , how to use node js , node js hello world , express node js , node js mongodb tutorial , nodejs http , why use node js

Related Searches to Node.js MySQL