# Looking for a Node.js module to filter file paths using glob patterns

**URL:** <http://community.latenode.com/t/looking-for-a-node-js-module-to-filter-file-paths-using-glob-patterns/13252>\
**Category:** NPM\
**Created:** [April 19, 2025, 7:12am UTC](http://community.latenode.com/t/looking-for-a-node-js-module-to-filter-file-paths-using-glob-patterns/13252 "2025-04-19T07:12:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OwenNebula55](http://community.latenode.com/letter_avatar_proxy/v4/letter/o/c89c15/32.png) [@OwenNebula55](http://community.latenode.com/u/OwenNebula55)\
**Post date:** [April 19, 2025, 7:12am UTC](http://community.latenode.com/t/looking-for-a-node-js-module-to-filter-file-paths-using-glob-patterns/13252/1 "2025-04-19T07:12:30Z")

</div>

I’m working on a project where I need to filter an array of file paths using glob patterns. Here’s what I’m trying to do:

```javascript
const allPaths = ['folder1/file1.txt', 'folder2/file2.js', 'folder3/subfolder/file3.css']
const matchedPaths = filterPaths(allPaths, 'folder2/**/*.js')

```

I’ve searched online but couldn’t find a straightforward npm package that does this. Does anyone know of a good module for this task? Or maybe there’s a simple way to do it without extra dependencies?

I know this might not be the best type of question to ask here, but I think it could be helpful for others working on similar file-handling tasks in Node.js. Any suggestions or tips would be appreciated!

---

<div class="post-metadata">

**Author:** ![alexr1990](http://community.latenode.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@alexr1990](http://community.latenode.com/u/alexr1990)\
**Post date:** [May 1, 2025, 7:15am UTC](http://community.latenode.com/t/looking-for-a-node-js-module-to-filter-file-paths-using-glob-patterns/13252/2 "2025-05-01T07:15:26Z")

</div>

hey man, have u checked out the ‘glob’ package? its pretty neat for this kinda stuff. i use it alot in my projects. its super easy to use, just npm install glob and ur good to go. it handles all sorts of patterns and its fast too. might be worth a look if ur still searching!

---

<div class="post-metadata">

**Author:** ![Grace\_31Dance](http://community.latenode.com/letter_avatar_proxy/v4/letter/g/58956e/32.png) [@Grace\_31Dance](http://community.latenode.com/u/Grace_31Dance)\
**Post date:** [April 30, 2025, 4:56am UTC](http://community.latenode.com/t/looking-for-a-node-js-module-to-filter-file-paths-using-glob-patterns/13252/3 "2025-04-30T04:56:26Z")

</div>

I’ve dealt with similar file path filtering challenges in my Node.js projects. While there are several options, I’ve found the ‘micromatch’ package to be incredibly reliable and efficient for this task. It’s lightweight, fast, and supports a wide range of glob patterns.

Here’s a quick example of how you could use it:

```javascript
const micromatch = require('micromatch');

const allPaths = ['folder1/file1.txt', 'folder2/file2.js', 'folder3/subfolder/file3.css'];
const matchedPaths = micromatch(allPaths, 'folder2/**/*.js');

```

It’s straightforward to use and handles complex patterns well. Plus, it’s actively maintained, which is crucial for long-term project stability. If you’re looking to avoid extra dependencies, you could explore the ‘path’ module combined with regex, but for complex patterns, a dedicated glob library like micromatch is often more robust and less error-prone.

---

<div class="post-metadata">

**Author:** ![DancingBird](http://community.latenode.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@DancingBird](http://community.latenode.com/u/DancingBird)\
**Post date:** [April 28, 2025, 4:06am UTC](http://community.latenode.com/t/looking-for-a-node-js-module-to-filter-file-paths-using-glob-patterns/13252/4 "2025-04-28T04:06:21Z")

</div>

For your file path filtering needs, I’d recommend looking into the ‘minimatch’ library. It’s a compact yet powerful solution that’s part of the npm ecosystem. I’ve used it in several projects, and it handles glob patterns efficiently.

Here’s a quick example of how you could use it:

```javascript
const minimatch = require('minimatch');

const allPaths = ['folder1/file1.txt', 'folder2/file2.js', 'folder3/subfolder/file3.css'];
const matchedPaths = allPaths.filter(path => minimatch(path, 'folder2/**/*.js'));

```

Minimatch is lightweight, which is great if you’re trying to keep your dependencies minimal. It’s also quite flexible and can handle complex patterns. Just remember to install it via npm before use. Hope this helps with your project!
