diff --git a/.gitignore b/.gitignore index 8b2fe56..02d6b0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules driver.txt drivers.json +stats.json .idea \ No newline at end of file diff --git a/app.js b/app.js index e39bbb8..7b6348c 100644 --- a/app.js +++ b/app.js @@ -83,8 +83,13 @@ schedule.scheduleJob("0 0 * * *", async () => { throw "Ergast API is unreachable and the drivers.json cache has not been built. Please try again when the Ergast API is online." } }) - let rawStatsFile = fs.readFileSync(statsPath) - let statsFile = JSON.parse(rawStatsFile) + let statsFile + if (fs.existsSync(statsPath)) { + let rawStatsFile = fs.readFileSync(statsPath) + statsFile = JSON.parse(rawStatsFile) + } else { + statsFile = {} + } let date = dayjs.format("YYYY-MM-DD") statsFile[date] = stats let newStatsFile = JSON.stringify(statsFile)