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

338
Vistas
does npm node-cache value can be set in one file and access in another

i am working on a nodejs app where i have to maintain an api token for 24hr and then refersh it, currently i am writing that token on json file in every update and it's not good for security, then i came to know about npm node-cache module but it seems it's value cannot be accessed in whole project(like setting in one file and accessing in another), is this how it works or m i missing something?

eg file 1

const NodeCache = require("node-cache");

const myCache = new NodeCache();

myCache.set("token", {token: "123", expirein: 123});

const test2 = require("./test2.js");

console.log(test2);

eg file 2 (test2.js)

const NodeCache = require("node-cache");

const myCache = new NodeCachae();

let c = myCache.get("token");
module.exports = c;

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

0

Don't create a new cache in each file. Create one global cache and use it everywhere.

cache.js

const NodeCache = require("node-cache");

module.exports = new NodeCache();

index.js

const myCache = require("./cache");

myCache.set("token", {token: "123", expirein: 123});

const test2 = require("./test2.js");

console.log(test2);

test2.js

const myCache = require("./cache");

let c = myCache.get("token");
module.exports = c;
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