Read all file names in a directory

Published on
1 mins read
––– views

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
v14.17.0

# Now it's good to go
$ node
> console.log(fs.readdirSync('./folder'))
[
  '.DS_Store',
  'authors',
  'blog',
  'headerNavLinks.js',
  'logo.svg',
  'projectsData.js',
  'siteMetadata.js',
  'snippets'
]