explaingit

isaacs/node-glob

8,713TypeScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

Node.js library for finding files using shell-style patterns like `**/*.js`, returns results as a promise, sync call, stream, or async iterator with optional file metadata.

Mindmap

mindmap
  root((node-glob))
    What it does
      File pattern search
      Shell-style patterns
      Metadata access
    Pattern syntax
      Star wildcard
      Double star recursive
      Curly brace lists
    Result modes
      Promise async
      Sync blocking
      Stream
      Async iterator
    Features
      Ignore rules
      File metadata
      Custom filters
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Find all files matching a pattern (e.g. `**/*.ts`) recursively in a project without writing a custom directory walker.

USE CASE 2

Stream matches from a large directory tree one file at a time to avoid loading all paths into memory at once.

USE CASE 3

Filter search results by modification time or permissions using built-in file metadata without extra filesystem calls.

Tech stack

TypeScriptNode.jsnpm

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This is a Node.js library that lets your JavaScript or TypeScript code search for files using patterns instead of exact names. You give it something like **/.js and it returns every JavaScript file in the folder tree, or .{png,jpeg} to match multiple image types at once. It is published on npm simply as glob (not node-glob, which is a different, abandoned package). The pattern language it uses is the same one that Unix shells like Bash understand: * matches any string within a single folder, ** crosses folder boundaries, ? matches a single character, and curly braces let you list alternatives. This makes it straightforward to describe file searches that would otherwise require writing a custom recursive directory walker from scratch. The library gives you several ways to receive results. The main glob() function is async and returns a promise that resolves to a list of matching file paths. globSync() does the same thing but blocks until it finishes. If you have a large folder tree, globStream() hands back matches one at a time as a stream, so you do not have to wait for every result before you start processing. An iterator form is also available for looping through matches one by one in a for-await loop. Beyond plain file path strings, glob can return richer path objects that include metadata like file size, permissions, and modification time. This lets you sort results by when a file was last changed or filter by read/write mode without making extra calls to the filesystem yourself. Ignore rules can be defined with patterns or with custom functions, giving you fine-grained control over which files and folders are skipped during the search walk. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Write a Node.js script using glob() to find all .ts files in src/ and filter them to only those modified in the last 24 hours using the stat metadata.
Prompt 2
How do I use globStream() in node-glob to process each matching file as it is found instead of waiting for the full result list?
Prompt 3
Show me how to pass an ignore option to glob to exclude node_modules and dist directories from a recursive pattern match.
Prompt 4
When should I use globSync() vs the async glob() function in a build script, what are the trade-offs?
Open on GitHub → Explain another repo

← isaacs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.