0

I am trying to import a variable from my main bot file to my database file. However, when it is read in my database file it comes back as an undefined object.

Main Bot File (Assume unspecified variables are declared - this is just a snippet):

// Reading the configuration YAML
var config;

try {
  config = yaml.load(fs.readFileSync('./config/config.yml', 'utf8'));
}

catch (e) {
  console.log(e);
}

console.log("> Loading config...")

console.log("> Loading modules...");
// Load Modules
module.exports = {
  bot: bot,
  config: config,
  commands: require('./commands'),
  events: require('./events'),
  utils: require('./utils'),
  database: require('./database'),
};

Database File:

const config = require('./bot');
const mysql = require('mysql2');

console.log(config);
// MySQL Pool Creation
var database = mysql.createPool({
    connectionLimit: config.sql.maxcons,
    user: config.sql.user,
    host: config.sql.host,
    password: config.sql.password,
    database: config.sql.database
});

module.exports = {
    database: database
  };

I recently updated NodeJS to the current version and I am unsure if something with module exports changed. I have been working on this for a while and cannot figure it out, any help would be appreciated! Thank you so much!

4

0 回答 0