Cannot return value with asyn function and setTimeout on node.js

I have a class which make a query into my db to get all configKeys and configValue for the website.

I have to immediatly set the value of application.config to the value returned by the callback of new Config

This is the master file -> application.js

var Application = require('Class').create({
initialize: function(rootPath) {
    this.rootPath         = rootPath;
    this.websitePath      = this.rootPath;
    this.websiteUrl       = null;
    this.adminPath        = './admin/';

    // Définition des chemins globaux
    this.globalPath       = this.rootPath + 'global/';
    this.modulePath       = this.globalPath + 'modules/';
    this.dbModulePath     = this.modulePath + 'db/';
    this.odbcPath         = this.globalPath + 'odbc/';

    // Définition des autres dossiers
    this.modelPath        = this.websitePath + 'models/';
    this.skinPath         = this.websitePath + 'skins/';
    this.viewPath         = this.skinPath + 'views/';

    // Définition des principaux fichiers
    this.commonFile       = this.modulePath + 'common.js';
    this.configFile       = this.modulePath + 'configuration.js';
    this.odbc             = this.odbcPath + 'mongoose.js';
    this.securityFile     = this.modulePath + 'security.js';

    // Définition des controllers
    this.modelFile        = this.globalPath + 'model.controller.js';

    // Définition des modules
    this.adminApplication = require(this.adminPath + 'application.js');
    this.cookieParser     = require('cookie-parser');
    this.express          = require('express');
    this.fs               = require('fs');
    this.swig             = require('swig');
},

loadConfig: function() {
    var self = this;

    // Initialisation de la configuration
    if ( this.fs.existsSync(this.configFile) ) {
        var Config  = require(this.configFile);
        new Config(function(config) {
            if ( config ) {
                self.config     = config;
                self.websiteUrl = self.config.WebsiteUrl;
            }
        });

        console.log(this.config); //return undefined because of async...
        debugger;
    }
    else {
        throw 'Cannot find the config file, please check that the file exists!\n';
    }

    // Initialisation de la class Common
    if ( this.fs.existsSync(this.commonFile) ) {
        var Common  = require(this.commonFile);
        this.common = new Common();
    }
    else {
        throw 'Cannot find the common file, please check that the file exists!\n';
    }

    // ODBC
    if ( !this.fs.existsSync(this.odbc) ) {
        throw 'Cannot find any ODBC, please check that the file exists!\n';
    }

    // Initialisation d'express
    this.app = this.express();

    this.app.set('type', 'front');
    this.app.set('case sensitive routing', true);

    // Config SWIG
    this.app.engine('html', this.swig.renderFile);
    this.app.set('view engine', 'html');
    this.app.set('views', this.viewPath);
    this.app.set('view cache', false);
    this.swig.setDefaults({cache: false});

    // On récupère les cookies sur chaque page
    this.app.use(this.cookieParser());
    // On déclare le dossier public accessible partout depuis le site
    this.app.use('/skins', this.express.static(this.skinPath));

    // Initialisation du Model Controller
    if ( this.fs.existsSync(this.modelFile) ) {
        var ModelController  = require(this.modelFile);
        this.modelController = new ModelController(this);
    }
    else {
        throw 'Cannot find the Front Model Controller, please check that the file exists!\n';
    }
},

start: function() {
    // On écoute sur le serveur au port 7777
    this.app.listen(7777, 'localhost');
}
});

module.exports = Application;

In application.js, I call configuration.js by doing 'new Config(function(config){..}' in the loadConfig method of Application.js

now this is the configuration.js file

var Configuration = require('Class').create({
initialize: function(callback) {
    this.host        = 'localhost';
    this.port        = 27017;
    this.database    = 'sgc';
    this.user        = 'xxx';
    this.pass        = 'xxx';

    this.loadConfig(callback);
},

loadConfig: function(callback) {
    var ODBC         = require('../odbc/mongoose.js');
    this.db          = new ODBC(this);

    var Configs      = require('./db/configs.js');
    this.configs     = new Configs(this.db);

    var queryResults = 0;
    var self         = this;


    this.db.find(self.configs.model, null, null, function(results) {
        for ( var rows in results ) {
            self[results[rows].ConfigKey] = results[rows].ConfigValue;
            queryResults                  = rows;
        }

        self.db.close();
        callback(self);
    });

    // db.find(this.configs.model, null, null, function(results) {
    //  for ( var rows in results ) {
    //      self[results[rows].ConfigKey] = results[rows].ConfigValue;
    //      queryResults                  = rows;
    //  }
    //  db.close();
    // });

    // function waitValues() {
    //  if ( queryResults > 0 ) {
    //      // console.log(self);
    //      // return self;
    //      callback(self);
    //      // result(queryResults);
    //  }
    //  else {
    //      setTimeout(waitValues, 100);
    //  }
    // }

    // waitValues();
}
});

module.exports = Configuration;

I have to use application.config later in the project because it must contain all the values found in the database (the values for the configuration of my website)

You need to pass in a callback to know when initialization is complete. Example:

var Configuration = require('Class').create({
  initialize: function(cb) {
    this.host        = 'localhost';
    this.port        = 27017;
    this.database    = 'sgc';
    this.user        = 'xxxx';
    this.pass        = 'xxxx';

    return this.loadConfig(cb);
  },

  loadConfig: function(cb) {
    var ODBC         = require('../odbc/mongoose.js');
    var db           = new ODBC(this);

    var Configs      = require('./db/configs.js');
    this.configs     = new Configs(db);

    var queryResults = 0;
    var self         = this;

    db.find(this.configs.model, null, null, function(results) {
      for ( var rows in results ) {
        self[results[rows].ConfigKey] = results[rows].ConfigValue;
        queryResults                  = rows;
      }

      db.close();

      cb();
    });
  }
});

Then you just call the function like:

config.initialize(function(err) {
  // next logic here ...
});

I'm not sure what module you're using for the database query, but typically you should pass any error that occurs to that callback (as the first argument).