Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda