Skip to main content

Quickstart

Scan a directory for files matching *.ts:
Match a string against a glob pattern:
The Glob class implements the following interface:

Supported Glob Patterns

Bun supports the following glob patterns:

? - Match any single character

* - Matches zero or more characters, except for path separators (/ or \)

** - Match any number of characters including /

[ab] - Matches one of the characters contained in the brackets, as well as character ranges

You can use character ranges (for example [0-9], [a-z]) and the negation operators ^ or ! to match anything except the characters in the brackets (for example [^ab], [!a-z]).

{a,b,c} - Match any of the given patterns

These patterns can be nested up to 10 levels deep and contain any of the earlier wildcards.

! - Negates the result at the start of a pattern

\ - Escapes any of the special characters above

Node.js fs.glob() compatibility

Bun also implements Node.js’s fs.glob() functions with additional features:
All three functions (fs.glob(), fs.globSync(), fs.promises.glob()) support:
  • Array of patterns as the first argument
  • exclude option to filter results