File system globs as a stream


NPM version Downloads Build Status Coveralls Status Gitter chat

A wrapper around node-glob to make it streamy.


var gs = require('glob-stream');

var stream = gs('./files/**/*.coffee', { /* options */ });

stream.on('data', function(file){
  // file has path, base, and cwd attrs

You can pass any combination of globs. One caveat is that you can not only pass a glob negation, you must give it at least one positive glob so it knows where to start. All given must match for the file to be returned.


globStream(globs, options)

Returns a stream for multiple globs or filters.


  • cwd
    • Default is process.cwd()
  • base
    • Default is everything before a glob starts (see glob-parent)
  • cwdbase
    • Default is false
    • When true it is the same as saying opt.base = opt.cwd
  • allowEmpty
    • Default is false
    • If true, won't emit an error when a glob pointing at a single file fails to match
  • Any through2 related options are documented in through2

This argument is passed directly to node-glob so check there for more options


var stream = gs(['./**/*.js', '!./node_modules/**/*']);

Globs are executed in order, so negations should follow positive globs. For example:

gulp.src(['!b*.js', '*.js'])

would not exclude any files, but this would

gulp.src(['*.js', '!b*.js'])


  • globby - Non-streaming glob wrapper with support for multiple patterns.