Working on Config system (Saving & Loading user data) #3

Merged
snxraven merged 16 commits from MiTask/LinkUp-P2P-Chat:main into main 2024-06-09 03:11:48 -04:00
Showing only changes of commit 2befd34039 - Show all commits

11
app.js
View File

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