lib/index.js
function init(options) {

    var fs = require('fs');
    var path = require('path');
    var rootdir = path.dirname(require.main);
    var options = options || {
        config: require(path.join(rootdir, 'config.json')),
        root: rootdir,
        callback: function (noop) {}
    };
    var def = {};
    function ModulePaths (moduledir) {
        this.moduledir = moduledir;
    }

    ModulePaths.prototype.then = function (accept, reject) {
      var moduledir = this.moduledir;
      fs.readdir(moduledir, function (err, files) {
        if (err) reject(err);
        files.forEach(function (file) {
            var name = path.basename(file, '.js');
            def[name] = path.join(moduledir, name);
        });
        accept();
      });
    };
    var pubpath = new ModulePaths(path.join(path.dirname(module.filename), '..', 'public', 'js'));
    var prvpath = new ModulePaths(path.join(path.dirname(module.filename), '..', 'private', 'js'));

    Promise.all([pubpath, prvpath])
        .then(function () {
            var requirejs = require('requirejs');
            requirejs.config({
                baseUrl: path.join(rootdir),
                paths: def
            });

            requirejs(['loader_factory'], function (LoaderFactory) {
                var fs = require('fs');
                var config = options.config;
                config.paths.push(path.dirname(pubpath.moduledir));
                var loader = 'loader_express';
                var db = 'db_mongo';
                if (config.loader) loader = config.loader;
                if (config.db) db = config.db;

                new LoaderFactory().create(loader, db, function (loader) {
                    loader.init(config, options.callback);
                });
            });
        })
    .catch(function (err) {
        console.error('err:', err);
    });
}
function init(options) {

    var fs = require('fs');
    var path = require('path');
    var rootdir = path.dirname(require.main);
    var options = options || {
        config: require(path.join(rootdir, 'config.json')),
        root: rootdir,
        callback: function (noop) {}
    };
    var def = {};
    function ModulePaths (moduledir) {
        this.moduledir = moduledir;
    }

    ModulePaths.prototype.then = function (accept, reject) {
      var moduledir = this.moduledir;
      fs.readdir(moduledir, function (err, files) {
        if (err) reject(err);
        files.forEach(function (file) {
            var name = path.basename(file, '.js');
            def[name] = path.join(moduledir, name);
        });
        accept();
      });
    };
    var pubpath = new ModulePaths(path.join(path.dirname(module.filename), '..', 'public', 'js'));
    var prvpath = new ModulePaths(path.join(path.dirname(module.filename), '..', 'private', 'js'));

    Promise.all([pubpath, prvpath])
        .then(function () {
            var requirejs = require('requirejs');
            requirejs.config({
                baseUrl: path.join(rootdir),
                paths: def
            });

            requirejs(['loader_factory'], function (LoaderFactory) {
                var fs = require('fs');
                var config = options.config;
                config.paths.push(path.dirname(pubpath.moduledir));
                var loader = 'loader_express';
                var db = 'db_mongo';
                if (config.loader) loader = config.loader;
                if (config.db) db = config.db;

                new LoaderFactory().create(loader, db, function (loader) {
                    loader.init(config, options.callback);
                });
            });
        })
    .catch(function (err) {
        console.error('err:', err);
    });
}
function init ( options ) { var fs = require ( 'fs' ) ; var path = require ( 'path' ) ; var rootdir = path . dirname ( require . main ) ; var options = options || { config : require ( path . join ( rootdir , 'config.json' ) ) , root : rootdir , callback : function ( noop ) { } } ; var def = { } ; function ModulePaths ( moduledir ) { this . moduledir = moduledir ; } ModulePaths . prototype . then = function ( accept , reject ) { var moduledir = this . moduledir ; fs . readdir ( moduledir , function ( err , files ) { if ( err ) reject ( err ) ; files . forEach ( function ( file ) { var name = path . basename ( file , '.js' ) ; def [ name ] = path . join ( moduledir , name ) ; } ) ; accept ( ) ; } ) ; } ; var pubpath = new ModulePaths ( path . join ( path . dirname ( module . filename ) , '..' , 'public' , 'js' ) ) ; var prvpath = new ModulePaths ( path . join ( path . dirname ( module . filename ) , '..' , 'private' , 'js' ) ) ; Promise . all ( [ pubpath , prvpath ] ) . then ( function ( ) { var requirejs = require ( 'requirejs' ) ; requirejs . config ( { baseUrl : path . join ( rootdir ) , paths : def } ) ; requirejs ( [ 'loader_factory' ] , function ( LoaderFactory ) { var fs = require ( 'fs' ) ; var config = options . config ; config . paths . push ( path . dirname ( pubpath . moduledir ) ) ; var loader = 'loader_express' ; var db = 'db_mongo' ; if ( config . loader ) loader = config . loader ; if ( config . db ) db = config . db ; new LoaderFactory ( ) . create ( loader , db , function ( loader ) { loader . init ( config , options . callback ) ; } ) ; } ) ; } ) . catch ( function ( err ) { console . error ( 'err:' , err ) ; } ) ; }
Node process entry

@author - Mark Williams
Entry point for node process. All bootstrapping activity is handled
by bootstrapping process in the loader created by factory
Node process entry