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

297
Visualizações
I seem to have accidentally made a fork bomb of some sort in nodejs, how can I fix it?

Below is my code for the /search page on my local webserver. I want to be able to update the page, and display the most recent search query. the problem is that by reloading the page, I end up running the portion that writes to a file (which inadvertently reloads the page) etc etc etc. Leading a vicious cycle of writing and reloading that can quickly get out of hand. Can you help me find a way to avoid this?

app.get('/search/', async (req, res) => {
    //console.log(req.body)
    // console.log(req.body.query)
    var act = null;
    var intervalId = setInterval(async function() {
        if (req.body.query) {
            act = await searchTweets(req.body.query);
        } else {
            act = await searchTweets("CVE")
        }
        fs.writeFile("./search.html", `<!DOCTYPE html> <html> <body>\n<a href='http://localhost:${port}/index.html' class='button'>Return to homepage</a>\n` + act + '\n</body>\n</html>', function(err) {
            if (err) {
                return console.error(err);
            }
        })
    }, 5000);
    fs.readFile("./search.html", 'utf8', function(err, data) {
        res.send(data);
        // Display the file content
        console.log(data);
    });

});

P.S. to monitor the file for changing I am using livereload: liverlserver.watch("../BasicServer");

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