-1

i want to read a json file data using fs.readFile in next.js 13.4 APIs in app router(directory) and parse it by JSON and display it. But it is showing the JSON content in console.log but not while i am returning it by NextResponse. Also there are very few resources from where i can take help for next.js 13.4 app router every resource is about pages router

I tried everything but nothing worked.

neel_G_ji
  • 17
  • 2
  • See [ask], then [edit] your question. Add what you've tried, add your code as a [mcve], be more specific than "nothing worked". – Robert May 24 '23 at 01:21

1 Answers1

0

Pretty sure you should just be able to import it, if it is a stable file name. I'm doing something like this:

'use client'

import HelloWorld from './hello.mdx';

import meta from './_meta.json';

export const pagemeta = meta;

export default function Page() {
    console.log("meta:", meta)
    return (
        <HelloWorld />
    )
}

I'm still new to next and trying to figure out how to read a bunch of these JSON objects (or MDX frontmatter) to generate a site menu with links to all the pages, so I have a related issue. I need to build a tree of this meta data and then pass some amount of it as context to the page, so I can have next/prev pages, so that I can print a list of child pages, ordered by some weight.

verdverm
  • 329
  • 4
  • 11