Adiiion Stack Overflow • Recommends
On “i am getting cannot read property 'query' of undefined”
It seems there is error in your mysql connection.try make proper connection first
Step 1: Create the pool (only do this once)
var mysql = require('mysql');
var pool = mysql.createPool({
host : 'hostname',
user : 'username',
password : 'password',
database : 'db_name',
connectionLimit : 10, // this is the max number of connections before your pool starts waiting for a release
multipleStatements : true // I like this because it helps prevent nested sql statements, it can be buggy though, so be careful
});
Step 2: Get a connection
pool.getConnection(function (err, conn) {
if (err)
return res.send(400);
// if you got a connection...
conn.query('SELECT * FROM table WHERE id=…