Functions: node-cron fetch from external api and write results to file

Hey @gregcarv,
I think iz… not possible. Netlify Functions are supposed to be ephemeral- no permanent storage, no IP address you can reliably access again. When you call one, it spins up on a random server somewhere and runs the code it’s supposed to run and then goes away. The next time you call it, it may spin up on a different server, maybe in a different region. So while you probably could write data to a file, it wouldn’t be accessible to you in the future because you likely wouldn’t be on the same filesystem. That said, if the response is small enough, maybe you wouldn’t have to write it out- you could just store it as a variable in memory?

Furthermore, Netlify abstracts away a lot of the complicatedness of AWS Lambdas (that’s what Netlify Functions are under the hood) but this also means you don’t have access to things you might if you were using AWS directly. This post may be interesting to you:

I also don’t think the cron job would work because, with the Jamstack, there’s no server at runtime. There are serverless workarounds (Hey, let's create a functional calendar app with the JAMstack | CSS-Tricks - CSS-Tricks) but I don’t know of a way to implement a cron job with Netlify Functions.

So probably not a good fit for what you’re trying to do. But Netlify Functions can do lots of other cool stuff if you wanna poke around in here:

Let us know if we can answer any other questions on this!