Back to Top

Node.js connection with database (mysql)

Updated 19 March 2013

Here are few steps to connect node.js with mysql.

You must have node.js installed in your environment. If not then visit http://webkul.com/blog/install-node-js-on-ubuntu/

1) install mysql on your environment. (write “npm install mysql” in ubuntu)

Now come to coding part. On server side add

2)

Start your headless eCommerce
now.
Find out More

var mysql = require(‘mysql’);
var connection = mysql.createConnection({
host : “your_host_name”,
user :”db_user”,
password : “db_pass”,
database : “db_name”,
});

“require” works at server side

now you can connect to database by adding

3) connection.connect();

Now your node.js is connected with database mysql.

Next task is to create and fetch data from database but the problem is:

-> Suppose we have a login form. Now on the click of button “login” we have to create entries in database. We have to give the action of button on client side but database cannot be connected at client side.So we must have a way to connect from client side to server side which i will discuss in my next blog.

HAPPY CODING..

 

. . .

Leave a Comment

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


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home