Next.js Discord

Discord Forum

Unable to read folder

Answered
DentFuse posted this in #help-forum
Open in Discord
Avatar
I'm getting a weird error where a folder exists but fs.readdirSync is unable to read it. I have attached my folder structure and the call stack is as follows:
utils/posts.js (6:20) @ fs

  4 | 
  5 | export function getAllPostIds() {
> 6 | const fileNames = fs.readdirSync(postsDirectory);
    |                  ^
  7 | 
  8 | // Returns an array that looks like this:
  9 | // [

Callstack
getAllPostIds
app/posts/[id]/page.js (52:29)
Image
Answered by DentFuse
const postsDirectory = path.join(process.cwd(), "posts");
View full answer

2 Replies

Avatar
const postsDirectory = "../posts";
Avatar
const postsDirectory = path.join(process.cwd(), "posts");
Answer