]> git.cworth.org Git - zombocom-ai/blobdiff - index.js
And now read in saved comments at server start
[zombocom-ai] / index.js
index 9279c877250c9e6055d142f9839dddd22dae775d..5e88926ae3e29db5bf7161a44e0deb10eb008d13 100644 (file)
--- 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() {