Say that I have a server module called server.js and an api module called api.js, server.js is the main module that i’m running.
Now, In the server, I have some functions that exports some data about the server,
In the api.js, I want to get some data from the server exported functions by adding: var api = require('./server.js');
The problem is that I get the server.js code running twice, first time when i’m running it, second when the api.js running the require('./server.js')
Any suggestions to bypass this issue?
Thanks
You should do it the other way around. Something like this:
In server.js:
In api.js: