简体   繁体   中英

global variable is not defined on node.js server in a cron file

I have a node.js server which has a global variable called Sys:

  const Sys = new require('../Boot/Sys');
  // Make Sys a global variable
  global.Sys = Sys;

I also have a file completely running separately using cron every minute the problem is that I need to modify the global variable in my cron file but it is undefined so my question is can I somehow define a global variable that is accessible in my cron file? im just starting to work with servers so forgive me if i am asking basics.

You should just be able to define the variable normally outside of the cron function. If for some reason that doesn't work you could use something like node-cache to cache the variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM