From 2befd340393f6fd3732d0285e4c5e0733db6de00 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sun, 9 Jun 2024 09:56:12 +0300 Subject: [PATCH] Ohh reading is async, thats why it didnt work --- app.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 796369d..2370063 100644 --- a/app.js +++ b/app.js @@ -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); }); }