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)
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..
Be the first to comment.