From c0e249ecdd9a86a88d15f93969fa5f1adde2f78f Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 6 Dec 2022 22:02:26 -0800 Subject: [PATCH] And now read in saved comments at server start So we should now have persistent messages across server restarts. --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9279c87..5e88926 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,17 @@ const { Server } = require("socket.io"); const io = new Server(server); const port = 2122; -comments = []; +const state_file = 'zombocom-state.json' + +var comments; + +// Load comments at server startup +fs.readFile(state_file, (err, data) => { + if (err) + comments = []; + else + comments = JSON.parse(data); +}); // Save comments when server is shutting down function cleanup() { -- 2.43.0