new to next.js trying to fetch data
Unanswered
Asian black bear posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Asian black bearOP
I have a file named db.json and I'm trying to parse it with a fetch request but it's failing. I'm trying to create a job board as a beginner project. The getJobs() function is async and I'm awaiting the response. Is there anyone who can help me?
6 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Plott Hound
follow this guide https://vercel.com/guides/loading-static-file-nextjs-api-route
tldr this:
import { promises as fs } from 'fs';
export default async function Page() {
const file = await fs.readFile(process.cwd() + '/app/data.json', 'utf8');
const data = JSON.parse(file);
return (
<div>
<h1>{data.title}</h1>
<p>{data.content}</p>
</div>
);
}
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Asian black bearOP
ty
I will try this out
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Plott Hound
no worries. let me know how you got on
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
you could import the json file instead