<commit_before>/**
 * Module dependencies.
 */
var express = require('express');
var http    = require('http');
var app     = express();

/*
    Load Model, Controller core
*/
var helper     = require('./_helper');
var model      = require('./model');
var controller = require('./controller');

module.exports = function(mode, callback) {
    /*
        Load config files
    */
    var settings = require(helper.getCallerPath('config/settings'));
    
    var hook_routes   = require(helper.getCallerPath('config/routes'));
    var hook_express  = require(helper.getCallerPath('config/express'));
    var hook_orm      = require(helper.getCallerPath('config/orm'));

    var setting;

    if(arguments.length === 1) {
        callback = mode;
        mode = null;
    }

    //load setting
    mode = mode || process.env.NODE_ENV || 'production';
    if(!settings[mode]) {
        return callback("Invalid Setting");
    }

    setting = settings[mode];

    //orm config
    model(app, {
        setting: setting.db, //orm setting
        hook: hook_orm,  //orm config hook
        path: helper.getCallerPath('models') //path to models folder
    }, function(err, database) {
        if(err) {
            console.log('Fail to load models');
            return callback(err);
        }
    });

    //express config hook
    hook_express(app);

    //routes
    controller(helper.getCallerPath('controllers'), function(err, controllers) {
        if(err) {
            console.log('Fail to load controllers');
            return callback(err);
        }
        
        hook_routes(app, controllers);
    });

    //create http server
    http.createServer(app).listen(setting.port, function(){
        console.log('Server is running');
        console.log('Mode: %s', mode);
        console.log('Port: %s', setting.port);

        callback(null);
    }).on('error', function(e) {
        if(e.code == 'EADDRINUSE') {
            console.log('Address in use. Is the server already running?');
        }

        callback(e);
    });
};<commit_msg>return express instance and orm database<commit_after>/**
 * Module dependencies.
 */
var express = require('express');
var http    = require('http');
var app     = express();

/*
    Load Model, Controller core
*/
var helper     = require('./_helper');
var model      = require('./model');
var controller = require('./controller');

module.exports = function(opt, callback) {
    if(arguments.length === 1) {
        callback = opt;
        opt = null;
    }

    var setting, mode, path;

    path = opt.path || helper.getCallerPath();

    //load config files
    var settings     = require(path + '/config/settings');
    var hook_routes  = require(path + '/config/routes');
    var hook_express = require(path + '/config/express');
    var hook_orm     = require(path + '/config/orm');

    //load setting
    mode = opt.mode || process.env.NODE_ENV || 'production';
    if(!settings[mode]) {
        return callback("Invalid Setting");
    }

    setting = settings[mode];

    //orm config
    model(app, {
        setting: setting.db,    //orm setting
        hook: hook_orm,         //orm config hook
        path: path + '/models'  //path to models folder
    }, function(err, database) {
        if(err) {
            console.log('Fail to load models');
            return callback(err);
        }

        //express config hook
        hook_express(app);

        //routes
        controller(path + '/controllers', function(err, controllers) {
            if(err) {
                console.log('Fail to load controllers');
                return callback(err);
            }
            
            hook_routes(app, controllers);
        });

        //create http server
        http.createServer(app).listen(setting.port, function(){
            // console.log('Server is running');
            // console.log('Mode: %s', mode);
            // console.log('Port: %s', setting.port);

            callback(null, app, database);
        }).on('error', function(err) {
            if(err.code == 'EADDRINUSE') {
                console.log('Address in use. Is the server already running?');
            }

            callback(err);
        });
    });
};
{'fraction_non_alphanumeric': 0.1463125444628883, 'fraction_numerical': 0.00047427080863172874, 'mean_word_length': 2.1129151291512915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1618653', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1151, 'n_words': 288}