-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.config.js
32 lines (25 loc) · 897 Bytes
/
api.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require("fs");
const path = require("path");
class Config {
constructor() {
this.buildConfigurations();
}
buildConfigurations() {
const configDirPath = path.join(__dirname, "config");
const allowedExtension = ".config.js"; // Only load config.js files
// Read all files from /config path
fs.readdirSync(configDirPath).forEach((file) => {
// Just load .js files
if (file.endsWith(".js")) {
// Get the name of the file without extension
const configName = file.replace(allowedExtension, "");
// Import file as module
const configModule = require(path.join(configDirPath, file));
// Asign the exported object from file as class property with clear name
this[configName] = configModule;
// -- console.log(`Config ${configName} loaded`);
}
});
}
}
module.exports = new Config();