Thanks for the resources. So yeah, Denis pretty much answered my question.
But in my case, I think I will go with the suggestion from this other post:
For anyone that comes to this post. I recommend that you consider if can you pre-compile multiple files into 1 file and just require that 1 file. For example, instead of serving multiple json files based on some logic, merge those json files into 1 file using something like bash.
# Folder Structure with compiled file
- route_data
- compiled.js
{
"home": .... data from file ....
"contact": .... data from file ....
"missing": .... data from file ....
}
- home.js
- contact.js
- missing.js
# read_dir_func.js
const fs = require('fs');
const path = require('path');
const compiled = require('../route_data/compiled.js');
.... logic ....