1

I have a folder called Songs in the Public folder. During render time I would like to render them:

const renderSongs = () => {
 [ array of song files ].map(song => {
  ...
 })
}

tho I dont think I can use fs in next.js, so how would i do this?

lowfi 2
  • 13
  • 5

1 Answers1

0

Note: You can import modules in top-level scope for use in getServerSideProps. Imports used in getServerSideProps will not be bundled for the client-side.

This means you can write server-side code directly in getServerSideProps. This includes reading from the filesystem or a database.

Source: https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation

or

https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering

So basically you can use fs, but only in the getStaticProps or getServerSideProps, which will be run at build time, or on the serverside.

tperamaki
  • 1,028
  • 1
  • 6
  • 12