/** * Load the individual file configurations. * * <p> * This method builds a map of filename to the configuration object defined * by the file. The search order is: * </p> * * <!-- 这里可以看到搜索配置文件及加载顺序 --> * <pre> * default.EXT * (deployment).EXT * (hostname).EXT * (hostname)-(deployment).EXT * local.EXT * local-(deployment).EXT * runtime.json * </pre> * * <p> * EXT can be yml, yaml, coffee, iced, json, cson or js signifying the file type. * yaml (and yml) is in YAML format, coffee is a coffee-script, iced is iced-coffee-script, * json is in JSON format, cson is in CSON format, properties is in .properties format * (http://en.wikipedia.org/wiki/.properties), and js is a javascript executable file that is * require()'d with module.exports being the config object. * </p> * * <p> * hostname is the $HOST environment variable (or --HOST command line parameter) * if set, otherwise the $HOSTNAME environment variable (or --HOSTNAME command * line parameter) if set, otherwise the hostname found from * require('os').hostname(). * </p> * * <p> * Once a hostname is found, everything from the first period ('.') onwards * is removed. For example, abc.example.com becomes abc * </p> * * <p> * (deployment) is the deployment type, found in the $NODE_ENV environment * variable (which can be overridden by using $NODE_CONFIG_ENV * environment variable). Defaults to 'development'. * </p> * * <p> * The runtime.json file contains configuration changes made at runtime either * manually, or by the application setting a configuration value. * </p> * * <p> * If the $NODE_APP_INSTANCE environment variable (or --NODE_APP_INSTANCE * command line parameter) is set, then files with this appendage will be loaded. * See the Multiple Application Instances section of the main documentation page * for more information. * </p> * * @protected * @methodloadFileConfigs * @param configDir { string | null } the path to the directory containing the configurations to load * @param options { object | undefined } parsing options. Current supported option: skipConfigSources: true|false * @return config {Object} The configuration object */ util.loadFileConfigs = function(configDir, options) {
// Initialize var t = this, config = {};
// Specify variables that can be used to define the environment var node_env_var_names = ['NODE_CONFIG_ENV', 'NODE_ENV'];
// Loop through the variables to try and set environment for (const node_env_var_name of node_env_var_names) { NODE_ENV = util.initParam(node_env_var_name); if (!!NODE_ENV) { NODE_ENV_VAR_NAME = node_env_var_name; break; } }
// If we haven't successfully set the environment using the variables, we'll default it if (!NODE_ENV) { //当未配置的时候,默认使用 NODE_ENV = 'development'; }