I have 2 js files in my node.js app
File a defines global object foo
In file b I can refer to foo.
But if file b is loaded before file a, then an error occurs.
I’m using node’s fs module to read the files. I use readdir, and then forEach require on every file. On my system the files are always read alphabetically, so there is never any problem.
Can I depend on those files being read alphabetically?
You can sort your array of files by name instead to be sure.