---
heading: 'Read file names'
title: 'Read all file names in a directory'
date: '2021-08-28'
icon: 'Bash'
draft: false
summary: 'A quick utility to read all file names in a directory using Node.js.'
tags: ['bash', 'shell', 'script']
---

Required: `node.js` installation.

Quickly get all files' names inside a folder

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

Example:

```bash showLineNumbers
# 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'
]
```
