Edit path for the metrics.json
This commit is contained in:
		
							
								
								
									
										13
									
								
								basics.js
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								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))
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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": [],
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user