From: Jérôme Benoit Date: Wed, 7 Oct 2020 20:08:07 +0000 (+0200) Subject: Use singleton design pattern for configuration file. X-Git-Tag: v1.0.1-0~304 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=83ee6a8646c702a561ba62f009e819c566243b90;p=e-mobility-charging-stations-simulator.git Use singleton design pattern for configuration file. Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Configuration.js b/src/utils/Configuration.js index 7fdfbe2d..7393626b 100644 --- a/src/utils/Configuration.js +++ b/src/utils/Configuration.js @@ -1,9 +1,14 @@ -const config = require('../assets/config.json'); +const fs = require('fs'); class Configuration { + static configurationFile; + // Read the config file static getConfig() { - return config; + if (!Configuration.configurationFile) { + Configuration.configurationFile = JSON.parse(fs.readFileSync('src/assets/config.json', 'utf8')); + } + return Configuration.configurationFile; } static getStatisticsDisplayInterval() {