i am trying to connect mysql, but it is showing me req.getConnection is not a function
Bellow is the code snipet which i have used. In app.js
var mysql = require('mysql'),
connection = require('express-myconnection'),
dbOptions = {
host: 'localhost',
user: 'root', password: '',
port: 3306,
database: 'nodejs'
};
app.use(connection(mysql, dbOptions, 'request'));
In Customers.js
exports.list = function(req, res, next) {
req.getConnection(function(err, connection) {
if (err) return next(err);
connection.query('SELECT * FROM customer', function(err, rows) {
if (err) console.log("Error Selecting : %s ", err);
res.render('customers', {
page_title: "Customers - Node.js", data: rows
});
});
});
};
Can you please check what is have done wrong. I am pretty new in nodejs, so may be i am missing something.
If you want to check my complete package, please follow bellow URL, i have push all code in my git repository https://github.com/chiraggmodi/nodeCrud
via Chirag S Modi
No comments:
Post a Comment