Ohh reading is async, thats why it didnt work

This commit is contained in:
MrMasrozYTLIVE 2024-06-09 09:56:12 +03:00
parent b577ff3207
commit 2befd34039

11
app.js
View File

@ -96,10 +96,9 @@ async function initialize() {
}
const configExists = fs.existsSync("./config.json");
console.log("Config exists:", configExists)
if (configExists) {
readConfigFromFile("./config.json");
console.log("Config:", config)
await readConfigFromFile("./config.json");
console.log("Read config from file:", config)
config.rooms.forEach(room => {
addRoomToList(room);
});
@ -430,9 +429,9 @@ function writeConfigToFile(filePath) {
});
}
function readConfigFromFile(filePath) {
fs.readFile(filePath, 'utf8', (err, data) => {
if(err) return console.error("Error while reading config.json! ", err);
async function readConfigFromFile(filePath) {
await fs.readFile(filePath, 'utf8', (err, data) => {
if(err) return console.log("Error while reading config.json! ", err);
config = JSON.parse(data);
});
}