Simple CURL cron job

Hi all. I’m new to netlify and love that I can use it to host simple web apps and static sites by just dragging the output folder structure.

From what I can tell Netlify doesn’t support cron jobs but has functions that can be configured to run periodically.

I’m trying to figure out the simplest way to call the following CURL command to periodically download the content of a URL to a file on the server:

"curl -o example.txt “https://www.example.com”.

import type { Config } from '@netlify/functions'
import { getStore } from '@netlify/blobs'

export default async function() {
  const res = await fetch('https://www.example.com/')
  const text = await res.text()
  await getStore('output').set('example.txt', text)
}

export const config: Config = {
  schedule: '@hourly'
}

Thanks for such a quick reply.

I created the simplest app possible to test with only two files. An “index.html” file at the root folder containing a link pointing to the expected download file and a “cron.ts” file in the netlify/functions folder containing the code provided above.

However when dragging and dropping to manually deploy the assets, the log says “No functions deployed”. Am I missing a trick?

Drag and deploy doesn’t deploy Functions.

Thanks again for the quick response. Using the netlify CLI to deploy to production instead of drag & drop added the functions.

However, the function is throwing an ImportModuleError: Cannot find module ‘@netlify/blobs’. Any idea what config I need to add to fix this?

Did you install @netlify/functions and @netlify/blobs as dependencies?

Sorry, completely new to this so didn’t know I had to. Assumed all netlify packages were OOTB.

So I’ve added the dependencies to my package.json as below:
{
“name”: “cron_example”,
“version”: “1.0.0”,
“dependencies”: {
@netlify/blobs”: “^9.1.2”,
@netlify/functions”: “^3.1.9”
}
}

However, I now get a " require() of ES Module from …not supported.". Any ideas?

I’d recommend using some online resources to continue further as debugging your code is outside our scope of Support. Based on just the provided details, I have no idea what you’re trying to require, but I’d recommend adding "type": "module" to your package.json.

That actually seems to have worked as I no longer get any errors. Thank you and I apologize for all the noob questions.

Hopefully one last question. With the code you initially provided above to save the content to a file:

await getStore(‘output’).set(‘example.txt’, text)

Where on the file system does it store the '‘example.txt’ file? The documentation is a little confusing.

Sorry for the followup question but going back to my original question. Is it even possible to permanently write to the file system from a netlify function?

It is not possible, @thesimplethingsinc. In the example given, the file is being saved using the blobs primitive:

Thanks for confirming that Luke.