Skip to content

Commit

Permalink
Merge pull request #595 from mountaindude/585-verify-config-file
Browse files Browse the repository at this point in the history
585 verify config file
  • Loading branch information
mountaindude committed Aug 21, 2023
2 parents ca03bf3 + 865ffa0 commit 320e05c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let configFileOption;
let configFileExpanded;
let configFilePath;
let configFileBasename;
let configFileExtension = 'yaml';
let configFileExtension = '.yaml';
if (options.configfile && options.configfile.length > 0) {
configFileOption = options.configfile;
configFileExpanded = path.resolve(options.configfile);
Expand All @@ -85,12 +85,21 @@ if (options.configfile && options.configfile.length > 0) {
console.log('Error: Specified config file does not exist');
process.exit(1);
}
} else {
// Set default values of environment variables controlling config file location and name
if (process.env.NODE_CONFIG_DIR === undefined) {
process.env.NODE_CONFIG_DIR = path.join(process.cwd(), 'config');
}

if (process.env.NODE_ENV === undefined) {
process.env.NODE_ENV = 'production';
}
}

// Set global variable conttaining the name and full pathof the config file
// Set global variable conttaining the name and full path of the config file
const configFile = path.join(
process.env.NODE_CONFIG_DIR,
process.env.NODE_ENV + configFileExtension
`${process.env.NODE_ENV}${configFileExtension}`
);

// Are we running as standalone app or not?
Expand Down Expand Up @@ -148,6 +157,13 @@ const logger = winston.createLogger({
),
});

// Show contents of environment variables controlling config file location and name
logger.debug(`NODE_CONFIG_DIR: ${process.env.NODE_CONFIG_DIR}`);
logger.debug(`NODE_ENV: ${process.env.NODE_ENV}`);

// Output config file name and path to log
logger.info(`Using config file: ${configFile}`);

// Function to get current logging level
const getLoggingLevel = () => logTransports.find((transport) => transport.name === 'console').level;

Expand Down

0 comments on commit 320e05c

Please sign in to comment.