Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
How do you get an array with the list of the files contained in a folder in Node.js?
First import the fs built-in module, then call fs.readdirSync() passing the folder name you want to read:
import fs from 'fs'
const filenames = fs.readdirSync('content')
You can use a relative or absolute path.
Then iterate over the file names:
filenames.map((filename) => {
console.log(filename)
})