Avinash Sinha Avinash Sinha - 7 months ago 23
SQL Question

How to install MySQL with Node.js & the node-mysql JavaScript Client

I am new on node.js and express.js, anyone please help me to get done it.

Answer

try this one

mkdir sp-node-mysql
cd sp-node-mysql
npm install mysql

and for connection as this

var mysql = require("mysql");

// First you need to create a connection to the db
var con = mysql.createConnection({
  host: "localhost",
  user: "jay",
  password: "jay"
});

con.connect(function(err){
  if(err){
    console.log('Error connecting to Db');
    return;
  }
  console.log('Connection established');
});