1

I run a SELECT query on a db in another module, and I wanted to export the values globally so I can use in other modules.

This is what I have at the moment:

./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 returns 'undefined', any idea why?

guilhermemrk
  • 35
  • 1
  • 7

0 Answers0