Can I read and parse static json file with cloudflare-workers? #1375
Replies: 2 comments
-
Hi @hectorAguero! You've raised an excellent point, and I've been contemplating the best approach to address it. Indeed, unlike Deno, Bunt, and Node.js, Cloudflare Workers doesn't have a conventional "file-system". This certainly complicates matters. I've experimented with the "Workers Sites" before, which serves assets for Cloudflare Workers via Cloudflare KV. Here's a relevant example for reference: https://github.com/yusukebe/ramen-api In this project, content JSON files are stored in the Workers Sites (KV), and content is retrieved using https://developers.cloudflare.com/workers/configuration/sites/ They now recommend Cloudflare Pages over Workers Sites. This leaves us with using KV, R2, or bundling everything into a single JavaScript file. None of these methods seem ideal. I've also contemplated creating a blog system that reads Markdown files, but I anticipate encountering a similar challenge. Let's keep this thread open and active. I'll consult with other developers at Cloudflare. |
Beta Was this translation helpful? Give feedback.
-
this is written in Hono docs |
Beta Was this translation helpful? Give feedback.
-
I had a json list file in my static folder that I use to search an item by id(basically like a table/document but small).
With Deno.readTextFile or node:fs/promises, is easy to do, but cloudflare workers doesn't support that.
Based on the docs I figure out I can do with serve static file, but I need to search inside the json also, so I need to retrieve the file, parse, search and return the item.
Edit: add code example
Beta Was this translation helpful? Give feedback.
All reactions