I'm asking this mostly as a sanity check, I'm unsure if I have made a mistake somewhere or if this fundamentally does not work.
I am converting some Java to Nodejs, A class called Site populates itself from a database via the dataFunctions.getSiteInfo(id) function. It also stores a list of Page instances.
The issue is that dataFunctions is returning as undefined when an instance of Site is created.
Have I misunderstood how classes and modules work in this case? Is it possible for instances of this class to access the dataFunctions module? Likewise is it possible for the Site class to reference the Page class as well? Or have I made some other silly mistake?
Site.js
let Page = require('./Page.js');
let dataFunctions = require('../DataFunctions.js');
module.exports = class Site {
constructor(id) {
this.id = id;
this.pages = [];
console.log(dataFunctions);
this.siteInfo = dataFunctions.getSiteInfo(id);
DataFunctions.js
let Site = require('./classes/Site.js');
function makeASite() {
let id = 2;
let site = new Site(id);
}
function getSiteInfo(id) {
etc etc
}
module.exports = {
getSiteInfo: function (id) {
return getSiteInfo(id);
},
};