How to properly pass mysql connection to routes with express.js

后端 未结 2 1814
太阳男子
太阳男子 2020-12-04 18:28

I am trying to figure out the best way to pass a mysql connection (using node-mysql) between my routes for express.js. I am dynamically adding each route (using a for each f

2条回答
  •  再見小時候
    2020-12-04 18:57

    your solution will work if use db() instead of new db(), which returns an object and not the db connection

    var db = require('../dbConnection.js');
    //var connection = new db();
    var connection = db();
    

提交回复
热议问题