I have index.js running the following code:
var ClassData=require("./server/classdata.js");
var data=require("./server/data.js");
The classdata.js file contains multiple classes, and I was wondering if there is any way to get that into data.js. As of now, the following code is:
var data={};
console.log("hello1"); //this gets logged
module.export=data;
console.log("hello2"); //this gets logged
console.log(ClassData); //"ClassData is not defined"
The data object gets exported when the last line is not there, otherwise with it there it says that ClassData is not defined.
I know I can probably define it using the same way I did in index.js, using require();, but I would think that makes it run the whole script again. Is there a way to just get it straight from data.js such that it is defined? Would I need to put it in the data.require part? I don't care if I can't change ClassData.
The classdata.js file contains multiple classes, and I was wondering if there is any way to get that into data.js
You can use require('./classdata.js') inside of data.js, that is what require is for, reusing a module inside another.
I know I can probably define it using the same way I did in index.js, using require();, but I would think that makes it run the whole script again.
Modules imported with require are cached after their first use so the script will not run again.