How can I share module-private data between 2 files in Node?

后端 未结 3 1901
深忆病人
深忆病人 2021-01-28 01:21

I would like to have a module for Node.js that is a directory with several files. I\'d like some vars from one file to be accessible from other file, but not from the files exte

3条回答
  •  野的像风
    2021-01-28 01:54

    Okay, you may be able to do this with the "global" namespace:

    //index.js
    global.foo = "some value";
    

    and then

    //extra.js
    var bar = global.foo;
    

提交回复
热议问题