Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

333
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!