Skip to content Skip to sidebar Skip to footer

Req.getconnection Is Not A Function In Express-myconnection

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'), connect

Solution 1:

You need to move this line:

app.use(connection(mysql, dbOptions, 'request'));

Right now, it's declared after your routes, which means that requests will never pass through it (that's how Express works: requests are passed through both middleware and route handlers in order of their declaration).

If you use it to a location in the code before the routes that require req.getConnection() to work (perhaps here), requests will first pass through the express-myconnection middleware and then get passed to the route handlers, making sure that req.getConnection() will be available inside those route handlers.

EDIT: on closer look, your customer routes are also incorrect.

You have this:

router.get('/', function(req, res, next) {
  res.render('customers', customers.list);
});

But customer.list is a route handler in itself, not something you should pass to res.render(). Instead, try this:

router.get('/', customers.list);

(and similarly for all the other routes in customers_route.js)


Post a Comment for "Req.getconnection Is Not A Function In Express-myconnection"