You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

glob

Package Overview
Dependencies
Maintainers
1
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob

a little globber

3.2.11
Source
npmnpm
Version published
Weekly downloads
213M
2.97%
Maintainers
1
Weekly downloads
 
Created

What is glob?

The glob npm package allows users to match file paths against specified patterns similar to how shell works. It is widely used for tasks such as file searching, filtering, and bulk operations on sets of files.

What are glob's main functionalities?

File Pattern Matching

Match files using the patterns the shell uses, like stars and stuff.

const glob = require('glob');

glob('**/*.js', function (er, files) {
  // files is an array of filenames.
  // If the `nonull` option is set, and nothing
  // was found, then files is ["**/*.js"]
  // er is an error object or null.
  console.log(files);
});

Synchronous File Pattern Matching

Perform a synchronous glob search.

const glob = require('glob');

const files = glob.sync('**/*.js');
// files is an array of filenames found matching the pattern.
console.log(files);

Pattern Matching with Promises

Use glob with Promises for better async control flow.

const glob = require('glob');
const util = require('util');
const globPromise = util.promisify(glob);

globPromise('**/*.js').then(files => {
  console.log(files);
}).catch(err => {
  console.error('Error occurred:', err);
});

Other packages similar to glob

FAQs

Package last updated on 20 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts