From 83ee6a8646c702a561ba62f009e819c566243b90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 7 Oct 2020 22:08:07 +0200 Subject: [PATCH] Use singleton design pattern for configuration file. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Configuration.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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() { -- 2.34.1