recurse

Takes a root dir and recursively streams paths

recurse

Takes a root dir and recursively streams paths.

var recurse = require('recurse');
 
// recursively write all filetypes except directories: 
recurse('.').pipe(process.stdout);
 
// recursively write js files: 
function js(relnamestat) {
  return !stat.isDirectory() && relname.match(/\.js$/)
}
recurse('.', {writefilter: js}).pipe(process.stdout);
 
// recursively write dirs: 
function dir(relnamestat) {
  return stat.isDirectory();
}
recurse('.', {writefilter: dir}).pipe(process.stdout);
 
// non-recursively write all files: 
function none(relnamestat) {
  return false;
}
recurse('.', {recursefilter: none}).pipe(process.stdout);
 
// recurse into test/ and write js files: 
function test(relnamestat) {
  return stat.isDirectory() && ~relname.indexOf('test');
}
recurse('.', {recursefilter: test, writefilter: js}).pipe(process.stdout);
var recurse = require('recurse');

Return a redable stream of all paths beneath a root directory.

Optionally pass in the following opts:

  • opts.writefilter - custom function for determining whether to write a path to the recurse stream using a opts.writefilter(relname, stat) signature.
  • opts.recursefilter - custom function for determining whether to recurse a path using a opts.writefilter(relname, stat) signature.
  • opts.resolvesymlinks - if set to true symbolic links will be resolved

Node 0.8.x will use the readable-stream module while node 0.10.x and newer will use the core Readable stream class.

recurse is about an order of magnitude slower than GNU find after a couple of runs on my home directory. See the benchmark for detailed results against other node modules.

MIT