Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
Node.JS reading json file isn't displaying new file updates

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; 

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!