I am having a hard time understanding how to export a file and then include it elsewhere on node.js.
Suppose I am working on a game and I want to have the variables which define an object, or more than one, for example a var enemy:
var enemy = {
health: 100,
strengh: 87
};
and I save it in a file vars.js.
How can one import these variables from anywhere in my project where I need them?
Thanks in advance.
You would need to export them.
So
Enemy.js:And in
otherjsfile.js:Side point:
If the ‘enemy’ information is changing periodically and you want to get the newest value, you would do: