talira

Glob matching for Node.js with negated patterns, directory expansion and .gitignore support

open sourceMITfree

globby is Sindre Sorhus's Node.js library for matching files with glob patterns, built on fast-glob. It takes several patterns at once, negated and negation-only patterns, expands a directory into everything under it, and respects .gitignore files the way Git does (including parent ones up to the repository root, and the global gitignore), or any ignore file with the same syntax such as .prettierignore. It has promise, sync and stream APIs and accepts a URL as the working directory.

Problems it solves

  • find files matching glob patterns in my Node.js script while skipping what .gitignore ignores
  • match files with several patterns and exclusions in one call in Node
  • list files in a directory tree without walking node_modules

Features

  • multiple and negated glob patterns
  • directory expansion
  • .gitignore and other ignore files, as Git applies them
  • promise, sync and stream APIs

Limitations

  • Patterns must use forward slashes: on Windows, patterns with backslashes silently fail1
  • ESM only and needs Node.js 20 or newer2

Alternatives

The same job

These do what globby does.

  1. glob Match files using the patterns the shell uses
  2. minimatch Glob matching for JavaScript, without regular expressions
  3. fast-glob Very fast and efficient glob library for Node.js
  4. del Delete files and directories by glob in Node.js, with a promise API
  5. rimraf rm -rf for Node.js, cross-platform

Compare globby with the top 3