Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Function not returning to another file

so I have a problem. I have two files, testMode.js and initialize.js, testMode.js requires initialize.js and runs the initialize functions, all works well until there's time to return back to testMode.js. In initialize.js, all works perfectly, when I print the user variable, it prints, but when I try returning the same variable, it is suddenly undefined in testMode.js.

Here is my code: testMode.js

// # MODULES #
const initModule = require('./initialize.js');

// # VALUES #
const botCmdChannel = process.env.BOT_COMMANDS_CHANNEL;

function error(issue) {
    console.log('An error has occured in test mode. Exiting with exit code 1. Error:' + issue);
    process.exit(1);
}


async function test(bot) {
    bot.login(process.env.TOKEN);
    bot.on('ready', async () => {
        console.log('Logged in successfully in test mode.');
        console.log('Attempting to initialize in test mode');
        const channelObj = bot.channels.cache.get(botCmdChannel);
        const message = await channelObj.send('Došlo k aktualizaci bota, probíhá test funkcí.');

        initModule.initialize(message, bot).then(function(response) {

            console.log(response);

            if (!response) {
                error(' Initialization failed.');
            } else {
                console.log('Initialization successful');
                process.exit(0);
            }

        });

        bot.on('error', issue => {
            error(issue);
        });
    });
    }


exports.testmode = test;

And the part of initialize.js that is not working:

       edupage.login(process.env.USER, decryptedpass, {
            edupage: process.env.SCHOOL
        }).then(user => {
            console.log('-----PŘIHLÁŠENÍ OK-----');
            sentembed3.delete();
            origmsg.channel.send({
                embeds: [embed4]
            });
            console.log('-----KONEC INICIALIZACE------');
            isInitialized = true;
            edupageuser = user;
            console.log(user) //works
            return user; //doesnt work
        }

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!