diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2024-03-07 22:33:55 +0000 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2024-03-07 22:33:55 +0000 |
| commit | bc220cc3cef8456e5de146288d3ec567153ca8e3 (patch) | |
| tree | 8a720fe7b9cf674117719a0fc8d5be4dc9edf31d /src | |
| parent | d2afcc667672145c784cfa9cd503ef881dea34f5 (diff) | |
Fixes fs problems
Diffstat (limited to 'src')
| -rw-r--r-- | src/db.js | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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){ |
