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

229
Vistas
Why doesn't setting NodeJS module cache to false get NodeJS to reload module?

I have 2 files, one named one.js and other name first.js.
one.js

var first = require("./first.js")
require.cache[first.module.id].loaded=false
require("./first.js")

first.js

console.log("First is running");
module.exports={module}

It's output is:

First is running

and not

First is running
First is running

as I expected. Why is it that even though I set the loaded property of the first.js module to false, it is still not being reloaded?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have to remove the cached module from the require.cache object to force node to load the module again. Node won't execute the module as long as it is in the require.cache.

One way to delete the module from the cache is shown below:

delete require.cache[require.resolve("./first.js")];

Side Tip: You could export a function from a module and just call that function again and again to have a similar result of loading the module everytime it is required.

about 4 years ago · Juan Pablo Isaza Denunciar
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