summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2024-03-07 22:33:55 +0000
committerJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2024-03-07 22:33:55 +0000
commitbc220cc3cef8456e5de146288d3ec567153ca8e3 (patch)
tree8a720fe7b9cf674117719a0fc8d5be4dc9edf31d
parentd2afcc667672145c784cfa9cd503ef881dea34f5 (diff)
Fixes fs problems
-rw-r--r--src/db.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/db.js b/src/db.js
index 16278c4..52652fd 100644
--- a/src/db.js
+++ b/src/db.js
@@ -1,7 +1,7 @@
// Ideally, we should write to a file and read it at app start in case of crashes.
// An actual SQL database would probably be overkill.
-const { readFileSync, writeFile } = require("fs");
+const fs = require("fs");
/** @type Array<{ name: string, number: string }> */
const subscriptions = [];
@@ -42,7 +42,7 @@ function getSubscriptionFromNumber(number) {
async function save() {
try {
- await writeFile('./data.json', JSON.stringify({ subscriptions }));
+ await fs.promises.writeFile('./data.json', JSON.stringify({ subscriptions }));
} catch (err) {
if (typeof err === 'string') {
console.error(`Error writing data: ${err}`);
@@ -54,7 +54,8 @@ async function save() {
function load() {
try {
- const data = JSON.parse(readFileSync('./data.json'));
+ const json = fs.readFileSync('./data.json');
+ const data = JSON.parse(json);
while (subscriptions.pop()) {}
subscriptions.push(...data['subscriptions']);
} catch (err){