From 097a1f11ff769dac92ec096153f12f0a5f145144 Mon Sep 17 00:00:00 2001 From: Raphix Date: Sat, 13 Jan 2024 17:10:12 +0100 Subject: [PATCH] Edit path for the metrics.json --- basics.js | 13 +++++++++---- main.js | 5 +++++ package.json | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/basics.js b/basics.js index 38df0ac..2dc6a5e 100644 --- a/basics.js +++ b/basics.js @@ -1,6 +1,7 @@ const fs = require("fs") const path = require("path") +var metricsPathFile = metricsPathFile module.exports.getDate = function (formated) { @@ -45,16 +46,20 @@ module.exports.getDate = function (formated) { } +module.exports.setMetricsFile = (path) => { + metricsPathFile = path +} + module.exports.getMetricsFile = () => { - if(!fs.existsSync(path.join(__dirname, "/metrics.json"))) { - fs.writeFileSync(path.join(__dirname, "/metrics.json"), JSON.stringify([], null, 2)) + if(!fs.existsSync()) { + fs.writeFileSync(metricsPathFile, JSON.stringify([], null, 2)) } else { - return JSON.parse(fs.readFileSync(path.join(__dirname, "/metrics.json"))) + return JSON.parse(fs.readFileSync(metricsPathFile)) } } module.exports.saveMetricsFile = (data) => { - fs.writeFileSync(path.join(__dirname, "/metrics.json"), JSON.stringify(data, null, 2)) + fs.writeFileSync(metricsPathFile, JSON.stringify(data, null, 2)) } \ No newline at end of file diff --git a/main.js b/main.js index da30e55..34a57cb 100644 --- a/main.js +++ b/main.js @@ -5,6 +5,11 @@ const basics = require('./basics.js'); const fs = require('fs'); +module.exports.setMetricFile = (path) => { + basics.setMetricsFile(path); +} + + module.exports.Metric = class { name; description; diff --git a/package.json b/package.json index 114d8d7..41b52a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webmetrik", - "version": "0.1.0", + "version": "0.1.2", "description": "NodeJS - npm package - Make metrics and make it available by making a httpServer", "main": "main.js", "keywords": [],