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

147
Vistas
Read fs without restarting server

I was using readdirsync() to get all the file names in a directory then send it to the front end and it works fine. The problem is if a new file is created in the directory after readdirsync run it the won't update the files name array to send to the back end. How can I listen if a new file exists and resend the data to the client-side without having to reload the server manually? Is this possible? Any help is appreciated. Thanks in advance.

const fs = require("fs");

var currentData = []
fs.readdirSync('./dirPATH').forEach(file => {
    currentData.push(file);
});

//what i tried but this won't work. still requires manual server restart:
function dataExchange() {
    app.post("/getData", (req, res) => {
        try {
            res.send(currentData);
        } catch (error) {
            console.log(error);
            res.status(400);
        }
    })
}

dataExchange()
setInterval(() => {
    dataExchange()
}, 2000)

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