lib/js/Server.js
function() {
      var t = this;

      // Test an app directory to see if it's a monitor app
      var testAppDir = function(dir) {

        // Load the package.json if it exists (and remove relative refs)
        var pkg;
        dir = Path.resolve(dir);
        try {
          pkg = JSON.parse(FS.readFileSync(dir + '/package.json', 'utf-8'));
        } catch (e) {
          // Report an error if the package.json has a parse problem.  This is
          // good during app development to show why we didn't discover the app.
          if (e.code !== "ENOENT") {
             console.error("Problem parsing " + dir + "/package.json");
          }
          return false;
        }

        // Is this a monitor-dashboard app?
        var isMonitorApp = pkg.dependencies && _.find(_.keys(pkg.dependencies), function(keyword){ return keyword === 'monitor-dashboard'; });
        if (!isMonitorApp) {
          return false;
        }

        // This is a monitor-dashboard app.
        return t.loadApp(dir, pkg);
      };

      // Process all apps under a node_modules directory
      var loadNodeModulesDir = function(dir) {

        // Return if the node_modules directory doesn't exist.
        try {
          FS.statSync(dir);
        } catch (e) {return;}

        // Check each direcory for a monitor-dashboard app
        FS.readdirSync(dir).forEach(function(moduleName) {

          // See if this is a monitor app, and load if it is
          // then load sub-modules
          var moduleDir = dir + '/' + moduleName;
          if (testAppDir(moduleDir) || moduleName === 'monitor') {

            // If it is a monitor-app, process any sub node_modules
            loadNodeModulesDir(moduleDir + '/node_modules');
          }
        });
      };

      // Test this app as a monitor app
      t.thisAppName = testAppDir('.');

      // Process all possible node_module directories in the require path.
      process.mainModule.paths.forEach(loadNodeModulesDir);

    }
function() {
      var t = this;

      // Test an app directory to see if it's a monitor app
      var testAppDir = function(dir) {

        // Load the package.json if it exists (and remove relative refs)
        var pkg;
        dir = Path.resolve(dir);
        try {
          pkg = JSON.parse(FS.readFileSync(dir + '/package.json', 'utf-8'));
        } catch (e) {
          // Report an error if the package.json has a parse problem.  This is
          // good during app development to show why we didn't discover the app.
          if (e.code !== "ENOENT") {
             console.error("Problem parsing " + dir + "/package.json");
          }
          return false;
        }

        // Is this a monitor-dashboard app?
        var isMonitorApp = pkg.dependencies && _.find(_.keys(pkg.dependencies), function(keyword){ return keyword === 'monitor-dashboard'; });
        if (!isMonitorApp) {
          return false;
        }

        // This is a monitor-dashboard app.
        return t.loadApp(dir, pkg);
      };

      // Process all apps under a node_modules directory
      var loadNodeModulesDir = function(dir) {

        // Return if the node_modules directory doesn't exist.
        try {
          FS.statSync(dir);
        } catch (e) {return;}

        // Check each direcory for a monitor-dashboard app
        FS.readdirSync(dir).forEach(function(moduleName) {

          // See if this is a monitor app, and load if it is
          // then load sub-modules
          var moduleDir = dir + '/' + moduleName;
          if (testAppDir(moduleDir) || moduleName === 'monitor') {

            // If it is a monitor-app, process any sub node_modules
            loadNodeModulesDir(moduleDir + '/node_modules');
          }
        });
      };

      // Test this app as a monitor app
      t.thisAppName = testAppDir('.');

      // Process all possible node_module directories in the require path.
      process.mainModule.paths.forEach(loadNodeModulesDir);

    }
function ( ) { var t = this ; // Test an app directory to see if it's a monitor app var testAppDir = function ( dir ) { // Load the package.json if it exists (and remove relative refs) var pkg ; dir = Path . resolve ( dir ) ; try { pkg = JSON . parse ( FS . readFileSync ( dir + '/package.json' , 'utf-8' ) ) ; } catch ( e ) { // Report an error if the package.json has a parse problem.  This is // good during app development to show why we didn't discover the app. if ( e . code !== "ENOENT" ) { console . error ( "Problem parsing " + dir + "/package.json" ) ; } return false ; } // Is this a monitor-dashboard app? var isMonitorApp = pkg . dependencies && _ . find ( _ . keys ( pkg . dependencies ) , function ( keyword ) { return keyword === 'monitor-dashboard' ; } ) ; if ( ! isMonitorApp ) { return false ; } // This is a monitor-dashboard app. return t . loadApp ( dir , pkg ) ; } ; // Process all apps under a node_modules directory var loadNodeModulesDir = function ( dir ) { // Return if the node_modules directory doesn't exist. try { FS . statSync ( dir ) ; } catch ( e ) { return ; } // Check each direcory for a monitor-dashboard app FS . readdirSync ( dir ) . forEach ( function ( moduleName ) { // See if this is a monitor app, and load if it is // then load sub-modules var moduleDir = dir + '/' + moduleName ; if ( testAppDir ( moduleDir ) || moduleName === 'monitor' ) { // If it is a monitor-app, process any sub node_modules loadNodeModulesDir ( moduleDir + '/node_modules' ) ; } } ) ; } ; // Test this app as a monitor app t . thisAppName = testAppDir ( '.' ) ; // Process all possible node_module directories in the require path. process . mainModule . paths . forEach ( loadNodeModulesDir ) ; }
Discover and load all node_monitor application modules

This is designed to run during server initialization, and is synchronous.

@method loadApps
Discover and load all node_monitor application modules