我在另一个模块的db上运行SELECT查询,我想全局导出值,以便可以在其他模块中使用。
这是我目前所拥有的:
./ app.js
var modules = require('./modules')
var m_db = modules.m_db
ayanami.on('ready', () => {
// Already tested and ConnectDB/CreateDB are working
const cnDB = m_db.ConnectDB.ConnectDB(config, config.dbFullPath);
const crDB = m_db.CreateDB.CreateDB(m_db);
// Created the vars because node said it wasn't declared
var botName, botLocale, botPrefix, botOkColor, botErrorColor, botLogColor, botDonoColor, botDateFormat;
// Called the module (I'll post it's code below)
const confDB = m_db.BotConfig.BotConfig(m_db);
// And tried to log a field from the db
console.log(botDateFormat);
// [...]
./ modules / index.js
var m_db = require('./db/index')
module.exports = { m_db }
./ modules / db / index.js
const ConnectDB = require('./connect');
const CreateDB = require('./create');
const BotConfig = require('./config');
module.exports = { ConnectDB, CreateDB, BotConfig }
./ modules / db / config.js
const BotConfig = (m_db) => {
db.each('SELECT * FROM bot_config', function(err, row){
var botLocale = row.locale
// [...]
var botDateFormat = row.dateformat
return botLocale, botDateFormat;
})
}
module.exports = { BotConfig }
botDateFormat返回“未定义”,为什么?