The `glob` package provides a robust and highly performant implementation for matching files using shell-like patterns in JavaScript. It is widely considered one of the most correct and fastest glob implementations available, supporting standard glob features such as wildcards, brace expansion, and extended globs. The current stable version is 13.0.6, and it targets modern Node.js environments (v18, v20, >=v22). The library emphasizes correctness according to shell standards and offers both synchronous and asynchronous APIs, including stream-based operations and an advanced `Glob` object for optimized, re-usable pattern matching. A key differentiator is its `withFileTypes` option, which returns enhanced `Path` objects (similar to `fs.Dirent`) for rich file metadata access and manipulation, including custom sorting and filtering based on file stats. It is actively maintained with a regular release cadence for bug fixes and feature enhancements.
npm install globVerified import paths — ran on the pinned version, not inferred.
Demonstrates asynchronous glob matching, multi-pattern support, iteration with the `Glob` class, and retrieving detailed file type information with stats.
Always use `npm install glob` and `import { ... } from 'glob'` or `require('glob')`.Consult the `glob` v13 documentation for current API signatures and return types. Migrate to named exports for all functions (`glob`, `globSync`, `globStream`, etc.) and the `Glob` class.
Wrap `await glob(...)` calls in an `async` function or ensure your environment supports top-level `await`.
Review the documentation for the `ignore` option. For simple patterns, use string/array. For advanced filtering, ensure your `ignored` and `childrenIgnored` functions are efficient and correctly handle `Path` objects if `withFileTypes` is used.
For CommonJS, use `const { glob } = require('glob');` then call `glob(...)`. For ESM, use `import { glob } from 'glob';`.Define an `async` function and call `glob` inside it, or enable top-level await in your Node.js environment (requires Node.js 14+ and ESM modules).
Increase your system's file descriptor limit (e.g., `ulimit -n 4096` on Unix-like systems) or use `globStream` for memory efficiency and to avoid opening too many files simultaneously.