1

I try to build an app through Nextjs, it is my first one. I've been building it successfully on the local environment, so I decided to publish it with my own domain, etc. I published it through Vercel. Here the thing: I have a json file where I read and write data into it. As I would like to get access to it, I put it in my public folder (no sensitive data at all) On the localhost environment

let content = await JSON.parse(fs.readFileSync('public/email.json'), 'utf8'))

works perfectly well and allows me to get access to the data. I have a same process for writing data

But when I pushed the data on the dev/prod environement, it does not work and I get those kind of error

{"error":{"errno":-2,"syscall":"open","code":"ENOENT","path":"public/email.json"}}

I've tried multiple things to correct the error, but as of today it was not possible to get access to email.json data

let content = await JSON.parse(fs.readFileSync(path.resolve(__dirname, 'email.json'), 'utf8'))

I'm sharing also my source code, through a screenshot, once it is deployed in Vercel Vercel source code

kev rabe
  • 67
  • 1
  • 3
  • Does this answer your question? [Next.js: How to get static assets from within getStaticProps](https://stackoverflow.com/questions/65860421/next-js-how-to-get-static-assets-from-within-getstaticprops/65861629#65861629) – juliomalves Jan 25 '21 at 09:55
  • Yes it is thanks a lot! – kev rabe Jan 26 '21 at 09:26

0 Answers0