I have a netlify function that needs to read all the files in a directory I created and then do some logic with that data. Everything works fine with my local build, the lambda function finds the files and does its job but when I publish it cannot find the directory. I am assuming it is because the server doesn’t keep the same directory structure.
How do I find the path to my other directory with the files?
Or how do I tell netlify that I need a certain function to access that directory?
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