dimanche 1 mars 2015

Node.js - Sharing variables between different files

I am new here and pretty new to Node.js. I got Express working fine, connecting to MySQL (database) is going fine, and socket io is working fine.


But I decided to split many of these features up in separated files. To keep my main JS file nice and clean. I made it possible to get variables from other js files back to my main.js script. Either using exports, or global. I find global working easier since most of them are functions. It's all working fine to this point.


But now the issue that I am having. I'm loading 3 js files in my main.js file. I am requiring the first js file, I call the function that is in that js file and store the result in a variable. That's going fine. But now the second js file is suppose to use or grab this variable, and that isn't working.


My question is, how do I make that work?


Aucun commentaire:

Enregistrer un commentaire