Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Read A Local File In Nextjs

This is done with [TODO: Code shorthand span ] which happens on the server side

js
export default function Page({fileAsString}) {
      return <div>{fileAsString}</div>
  }

  export async function getStaticProps(context) {
    try {
      const fileText = fs.readFileSync(
        `./pages/switch-components-via-state.js`,
        `utf8`
      )
      return {
        props: {
          fileAsString: fileText,
        },
      }
    } catch (err) {
      console.log(err)
      return {
        props: {
          fileAsString: `could not find file`,
        },
      }
    }
  }

Note that in the node docs [TODO: Code shorthand span ] is included via [TODO: Code shorthand span ] but here it's done with [TODO: Code shorthand span ]