I have two configuration files (log.txt, and config.json) that are updated after each computation and the next computation is dependent on the results of the previous computation which are stored in the two files. The problem is, when I read the json files during computation I only get the results of the initial first computation. The new updates are not reflected in the new file reads. But when I check the files, both have been updated. What could be the problem? Thanks in advance.
Script for Reading the configuration files (pFunctions.js):
const fs = require('fs');
// Read logs
function readLog() {
try {
return fs.readFileSync(__dirname + '/' + 'log.txt', {'encoding':'utf8','flag':'rs+'});
}
catch (err) {
return '';
}
}
// Read configurations
function readConfig() {
try {
return fs.readFileSync(__dirname + '/' + 'config.json', {'encoding':'utf8','flag':'rs+'});
}
catch (err) {
return '';
}
}
// Function to read dataset
function readDataset() {
....
....
}
// Read data from configuration files
let config = readConfig(); // config.json
let log = readLog(); // log.txt
// Parse data to JSON
let cfg = JSON.parse(config);
let lcg = JSON.parse(log);
....
....
// Fetch dataset based on the configuration and log file
let dataset = readDataset();
// Create parameter function
const pFunctions = {
parameter1: dataset // set dataset as value of parameter1
}
// Export function as JSON Object
module.exports={pFunctions};
I then import the object in the computation.js script like this:
const {pFunctions} = require('./app/config/pFunctions');
// Capture new 'uParams' computing parameters
let newParams = pFunctions;