Next.js Discord

Discord Forum

How do I write to a JSON if I'm deployed on Vercel?

Answered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
I have an app which has [API endpoints](https://github.com/louisuy/employee-supervisors/blob/main/app/api/employees/route.js) to read and write from a JSON file stored in "@/data/employees.json" but this doesn't work on Vercel because of the serverless nature and how it doesn't allow writing to the fs.

The [JSON](https://github.com/louisuy/employee-supervisors/blob/main/data/employees.json) structure is unconventional and restructuring it with keys (or using a db conventionally) would make it stray from the brief.

How can I read and write to a JSON using the same app? This logic works for when it is stored locally and through localhost:3000, just need insight how I could do this on a deployed app.
Answered by linesofcode
You could consider using vercels kv service for a simple key value store on top of upstash. https://vercel.com/docs/storage/vercel-kv
View full answer

6 Replies

It’s impossible to write data to a file system in vercel
You could consider using vercels kv service for a simple key value store on top of upstash. https://vercel.com/docs/storage/vercel-kv
Answer
Also, I have an alternative solution for you if your data needs are simple
You can leverage GitHub gist as a very basic json database
However this is only good hobby projects where you don’t have a lot of writes or need transactional guarantees
Checkout my npm package gist-database