Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda