Use singleton design pattern for configuration file.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 7 Oct 2020 20:08:07 +0000 (22:08 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 7 Oct 2020 20:08:07 +0000 (22:08 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/utils/Configuration.js

index 7fdfbe2d77a0fb360197e403165b1e7d4d0eab0a..7393626be78e39c2bf758dbf39ff79620f8e27c3 100644 (file)
@@ -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() {