如何在同一模块内调用模块的方法?

时间:2019-09-03 08:41:56

标签: node.js express

我创建了一条路线:

var connexion = require('./dbMysql');

exports.getPrefixNomTables = function () {
    return "george_";
};

exports.getRegionIdFromLib = function (regionLib, cb) {
    var ret = 0;
    connexion.query("select region_id from george_region where region_libelle = ? limit 1", [regionLib], (err, rows) => {
        if (err) {
            throw err;
        }
        if (rows.length > 0)
            ret = rows[0].region_id;
        cb(ret);
    });
};

getRegionIdFromLib函数中,我想调用getPrefixNomTables方法,而不是对george_region进行硬编码。该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以在exports.getPrefixNomTables()内致电getRegionIdFromLib

exports.getRegionIdFromLib = function (regionLib, cb) {

  var region = exports.getPrefixNomTables()

  // ...

};