diff --git a/index.js b/index.js index c51b785..a5ea242 100644 --- a/index.js +++ b/index.js @@ -25,8 +25,11 @@ function sendMessage(message) { } async function compareAndSave(productsPrice) { - const productsPriceJson = - fs.readFileSync("productsPrice.json", "utf8") || "[]"; + if (!fs.existsSync("productsPrice.json")) { + fs.writeFileSync("productsPrice.json", "[]"); + } + + const productsPriceJson = fs.readFileSync("productsPrice.json", "utf8"); const oldProductsPrice = JSON.parse(productsPriceJson); const diffProducts = []; @@ -139,7 +142,7 @@ async function init() { await compareAndSave(productsPrice); - console.log("Done! Check productsPrice.json"); + console.log("Sprawdzone! Aktualne ceny zapisane w productsPrice.json"); } sendMessage("Zaczynam monitoring cen");