Variables not being updated in node.js asynchronously

I'm new to node.js and I have some code that isn't working properly. I think the issue is in asynchronous functions. This code is pretty simple. Read some xml, assign the values to variables, assign those variables as properties that are used to connect to a database in another node.js file. Problem is the variables don't update after reading the xml.

Loading configuration files is probably the best use-case for blocking file I/O in node (IMHO). Just use fs.readfileSync() instead.

Otherwise, if you must keep async file reading (which I doubt is the case, when you're trying to load your configuration values for startup), don't try exporting the values directly. Instead, export a function which will provide those values to either a callback or a promise, then use that function instead. You can add some sort of caching mechanism if you need these config values in multiple locations and you want to make sure the file is only read once.

Truth be told (and I'm not sure if this is an option for you), the simplest solution would be ditch the idea of a configuration file altogether, and then to provide the configuration you are looking for (user, server, password, etc) with environment variables, and then reading them from process.env.

Email codedump link for Variables not being updated in node.js asynchronously