Req.getconnection Is Not A Function In Express-myconnection
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"