I'm new to node.js but have developed enough server-side code that exporting and requiring a file for each custom-written library function is getting unwieldy. I've been reading about alternatives and am confused--perhaps because I should compromise on my goal.
There are 3 separate reusable .js files that are part of one logical kind of task. Let's call the task-type, "x".
- xLibrary.js - misc utilities specific to that task - many functions
- xSubtask1.js - some complex code and supporting functions
- xSubtask2.js - some complex code and supporting functions
I understand how to proceed if I treat each file as a separate module with a separate variable that references it. But since the subtasks are arbitrarily segregated (due to complexity not logical association) it creates confusion to have to remember which file contains a given function.
I'd like to put all the modules in 1 subdirectory and reference all the functions as xTask.*. The only way I know to do that is to combine all the files into one, but that makes maintaining the code more complex.
I've read articles and stackoverflow until my head is spinning. Many of the more comprehensive answers use logic to add each module in a subdirectory. I think hard-coding function and file names is more appropriate for my current level of expertise.
Can someone tell me how to proceed?