Edit path for the metrics.json

This commit is contained in:
Raphael 2024-01-13 17:10:12 +01:00
parent 902f2812f0
commit 097a1f11ff
3 changed files with 15 additions and 5 deletions

View File

@ -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))
}

View File

@ -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;

View File

@ -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": [],