0

I am trying to fetch my own data before rendering my application. Fortunately, Next.js provides getStaticProps() for fetching data.

I am currently using fs module to fetch my data from json file in local directory.

export async function getStaticProps() {
  const rawData = fs.readFileSync('./dataset/test.json');
  const data = modifyData(JSON.parse(rawData));
  return {
    props: {
      data
    }
  }
}

But the problem is, for securing my raw data, I didn't push them to the GitHub remote repository. Forgetting this, when I tried to deploy my app through vercel, it couldn't read any data from my GitHub repository as the repository does not contain any data to fetch from...

I don't want to push my raw data to GitHub.

I would like to know

  • the best practice to fetch raw data without pushing any of them to the remote repository

If there are some fundamentals of Next.js or any other I missed, please let me know and correct me.

1 Answer 1

2

Being "serverless", you've got to host your data somewhere, in a database or as a file.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you please elaborate it more? I read links you provided and googled some more. It seems like, if I want to use a file as a data, then I should upload it in serverless (such as AWS S3) and fetch it using api in Next.js. Is it right? Before I deep dive into each concepts, I will be happy if I roughly understand the whole process

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.