Using Node.js file system is it smarter to run through 80 files looking for a property than it is to run through conditions in one file?

StackOverflow https://stackoverflow.com//questions/25079469

Question

Let me explain: I am building a node.js project that needs to check if dates match or fall within a range. If there is a match, I need to store a reference to the path of a file on the server. There are about 80 of these files. They are configurations.

I can write a giant condition in a function that can run through and check the dates. It will be fast, I'm sure. The real question is, is it smarter to let each config file store it's own date (the date is a calculation based on a date that will have to be passed in to the config file), then loop through the files, requiring each one, finding the property holding the date, checking it, then either storing the files path or not?

The requiring approach will be much less code, and it will be cleaner, but I'm wondering if I will take a huge performance hit. Is it better to just write a giant list of conditions?

Sorry if this is not clear. Let me know if I need to include anything to help clarify the question.

Was it helpful?

Solution

the date is a calculation based on a date that will have to be passed in to the config file

Then don't put the calculation result in the config file as well, but store it in memory.

On startup, run through all 80 files (in parallel?), collect the dates and do the respective calculations. Store the results in an array or so.
On each request, write a loop (not a giant hand-written condition!) to find the date, and use the file path associated to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top