Leo's dev blog

Read all file names in a directory

Published on
Published on
/1 mins read/---

Required: node.js installation.

Quickly get all files' names inside a folder

console.log(fs.readdirSync('./folder-path'))

Example:

# Make sure node.js installed
node -v
v22.9.0
 
# Now it's good to go
node
> console.log(fs.readdirSync('./folder'))
[
  '.DS_Store',
  'authors',
  'blog',
  'headerNavLinks.js',
  'logo.svg',
  'projectsData.js',
  'SITE_METADATA.js',
  'snippets'
]