Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
balanced-match | 1.0.2 | 2.61 kB | MIT | prod | |
brace-expansion | 1.1.11 | 4.14 kB | MIT | prod | |
concat-map | 0.0.1 | 2.21 kB | MIT | prod | |
fs.realpath | 1.0.0 | 4.33 kB | ISC | prod | |
glob | 7.1.7 | 15.41 kB | ISC | prod | |
inflight | 1.0.6 | 1.99 kB | ISC | prod | |
inherits | 2.0.4 | 1.98 kB | ISC | prod | |
minimatch | 3.1.2 | 11.66 kB | ISC | prod | |
once | 1.4.0 | 1.93 kB | ISC | prod | |
path-is-absolute | 1.0.1 | 1.84 kB | MIT | prod | |
wrappy | 1.0.2 | 1.64 kB | ISC | prod |
Glob is a widely-used npm package that matches files using the same patterns as the shell. Regarded as one of the most accurate and efficient glob implementations in JavaScript, Glob helps you match and handle files and directories following specific patterns. Using this package, you can conveniently match, ignore, search, and filter files using patterns like *.js
(for matching all JavaScript files), **/*.txt
(for matching all text files in all directories), and many more.
Before you can use Glob, you need to install it in your Node.js project using npm. The npm package name is "glob". Install it by running npm i glob
in your project directory.
After installation, you can import or require Glob in your JavaScript file. Glob provides several methods that you can use, including glob
, globSync
, globStream
, and globStreamSync
. You can also use the Glob
class to perform glob pattern traversals multiple times, which can be faster if you need to look in the same folder multiple times.
Here's a code example:
// Import Glob
import { glob, globSync } from 'glob';
// Match all .js files but ignore those in node_modules
const jsfiles = await glob('**/*.js', { ignore: 'node_modules/**' });
// Use globSync for synchronous operation
const imagesAlt = globSync('{css,public}/*.{png,jpeg}');
Note that Glob always uses /
as a path separator, regardless of the operating system.
The official Glob documentation is comprehensive and provides detailed usage examples, information about different options you can use with Glob methods, comparisons to other glob implementations, and clarifications on Glob's behavior concerning different filesystem entities. The documentation also includes details about Glob's command-line interface for extra flexibility and convenience. Additionally, you can gain insights into Glob's internals by checking out the source code on its GitHub repository.