Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ls-stream with all npm packages installed. Try it out:

var lsStream = require("ls-stream")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ls-stream v1.0.0

readable stream of file paths + stat objects


a readable stream of file and directories paths and entries.

var ls = require('ls-stream')

    .on('data', console.log.bind(console))


ls([fs,] directory) -> ls stream

create a readable stream of entry objects.

will start emitting data on next tick unless paused.

users may optionally provide their own fs object if native fs is not available for whatever reason (e.g., in browser).

'data' Entry object

{ path: "path/to/file-or-dir"
, stat: fs.Stat object }

Entry.ignore([bool=true]) -> undefined

If called on the same event loop turn as the event is received, prevents recursing into this directory (or is a no-op if the entry represents a file). Optionally takes a single argument which defaults to true to set the "ignored" status.

var through = require('through')
  , ls = require('ls-stream')

  .pipe(through(function(entry) {
    if(entry.path == "/path/something") {
      // if we see "/path/something" *don't* list files
      // and dirs that it contains.

Warning: As aforementioned, this only works if the entry is ignored on the same event loop turn. For example, the following code would fail to ignore the given entry:

// WARNING: this will not work:
  .pipe(through(function(entry) {
    // by the time we tell the entry that it
    // should be ignored, `ls` has already
    // recursed into it!
    setTimeout(function() {
    }, 0)




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free