config.js 802 B

1234567891011121314151617181920212223242526272829
  1. const fs = require('fs');
  2. // Chemin vers le fichier
  3. const path = './config.json';
  4. // Verif que le fichier de config existe
  5. if (!fs.existsSync(path)) {
  6. throw "Config file not found";
  7. }
  8. // Lecture du fichier
  9. const data = fs.readFileSync(path).toString();
  10. const config = JSON.parse(data);
  11. // Verification de la presences des différents elements
  12. if (config.storage === undefined) {
  13. throw 'Storage undefined in the config file';
  14. } else if (config.auth === undefined) {
  15. throw 'Auth undefined in the config file';
  16. }
  17. //Verification valeur
  18. if (config.storage !== 'database' && config.storage !== 'file') {
  19. throw 'Bad value for storage: database or file expected';
  20. } else if (typeof config.auth !== 'boolean') {
  21. throw 'Bad value for auth: boolean expected';
  22. }
  23. module.exports = config;