# Node.js get all files in a folder recursively

> Learn how to get all the files in a folder recursively in Node.js using the glob library and a pattern like /**/index.md to match files in any subfolder.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2022-05-20 | Topics: [Node.js](https://flaviocopes.com/tags/node/) | Canonical: https://flaviocopes.com/nodejs-get-all-files-folder/

I had the need to get all the files in a folder recursively.

The best way I found to do that was to install the [`glob` library](https://www.npmjs.com/package/glob):

`npm install glob`

If you're not sure your glob pattern matches the files you expect, you can try it in my [glob pattern tester](https://flaviocopes.com/tools/glob-tester/).

I wanted to look for all `index.md` files included in the `content/post` folder, each file being in its own directory structure, possibly under multiple subfolders:

- `content/post/first/index.md`
- `content/post/second/index.md`
- `content/post/another/test/index.md`

Here's how I did it:

```js
const glob = require('glob')

const root_folder = 'content/post'

glob(root_folder + '/**/index.md', (err, files) => {
  if (err) {
    console.log('Error', err)
  } else {
    console.log(files)
  }
})
```
