Let's say I do:
eval(
db_config = {
host: 'localhost',
user: 'root',
database: 'forum',
password: 'test'
}
);
var gamefunctions = require('gamefunctions.js');
I can use db_config
anywhere inside gamefunctions.js
without having to pass it through a parameter. That's pretty neat. But, is this bad practice?
Reason I ask this is because if I do:
var db_config = {
host: 'localhost',
user: 'root',
database: 'forum',
password: 'test'
}
var gamefunctions = require('gamefunctions.js');
db_config
becomes undefined anytime I use it in gamefunctions.js
. And I would have to pass it through a parameter on each different function which just seems like evaling
it first would save time and code, any downside to this?
Does eval
basically just define the variables in a global scope for you, so they can be used in any file in nodejs?