I am reading the content of .md files and want to display it
<code>import fs from "fs";
import matter from "gray-matter";
export default function getHubMetadata() {
const folder = "hubs";
const files = fs.readdirSync(folder);
const hubs = files.filter((file) => file.endsWith(".md"));
const hubPosts = hubs.map((filename) => {
const fileContent = fs.readFileSync(`${folder}/${filename}`, "utf8");
const matterResult = matter(fileContent);
return matterResult;
});
return hubPosts;
}
</code>
<code>import fs from "fs";
import matter from "gray-matter";
export default function getHubMetadata() {
const folder = "hubs";
const files = fs.readdirSync(folder);
const hubs = files.filter((file) => file.endsWith(".md"));
const hubPosts = hubs.map((filename) => {
const fileContent = fs.readFileSync(`${folder}/${filename}`, "utf8");
const matterResult = matter(fileContent);
return matterResult;
});
return hubPosts;
}
</code>
import fs from "fs";
import matter from "gray-matter";
export default function getHubMetadata() {
const folder = "hubs";
const files = fs.readdirSync(folder);
const hubs = files.filter((file) => file.endsWith(".md"));
const hubPosts = hubs.map((filename) => {
const fileContent = fs.readFileSync(`${folder}/${filename}`, "utf8");
const matterResult = matter(fileContent);
return matterResult;
});
return hubPosts;
}
I have a route /project-hub and another route /project-hub/[slug]
the function works perfectly on my pc even the build one, but on Vercel, the function works only in /project-hub. It gives me an error : ENOENT: no such file or directory, scandir ‘hubs’
Tried to add my hubs folder everywhere, tried to use path module but still not working on vercel
New contributor
Anomaly is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.