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

339
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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