npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

listdirs

v3.1.1

Published

List all directories recursively given an inital directory

Downloads

238

Readme

listdirs

List Directories asynchronously in node.js.

Build Status codecov Dependency Status npm version Node.js Version

Why?

We needed an easy way of listing all the directories in a project so we could watch them for changes.
We reviewed many available options and found them lacking in one of the following areas:

  1. Untested (or incomplete tests)
  2. Patchy documentation (often none)
  3. Unmaintained or Abandoned (many open/unaddressed issues on GitHub)
  4. Unclear code (written without shoshin)
  5. Too Many Features trying to do too much. (we only need one thing a list of the directories)

too many features

What?

Given an initial directory (e.g. the Current Working Directory) give me a list of all the "child" directories.

How? (Usage)

Install from NPM

npm install listdirs --save

In your code:

var listdirs = require('listdirs');
var basedir = __dirname; // or which ever base directory you prefer
listdirs(basedir, function callback(err, list){
    if(err){
      console.log(err); // handle errors in your preferred way.
    }
    else {
      console.log(list); // use the array of directories as required.
    }
});

(Optional) Supply a List of Files/Directories to Ignore

If you have a large project and want to ignore the files in your .gitignore file (e.g. node_modules), there's an easy way to do this:

var listdirs = require('listdirs');
var ignored  = require('ignored')('./.gitignore'); // https://github.com/nelsonic/ignored
var basedir  = __dirname; // or which ever base directory you prefer
listdirs(basedir, function callback(err, list){
    if(err){
      console.log(err); // handle errors in your preferred way.
    }
    else {
      console.log(list); // use the array of directories as required.
    }
}, ignored); // include ignored list as 3rd Parameter (after callback)

Note: This example uses our ignored module: https://www.npmjs.com/package/ignored as an optional helper to list the entries in .gitignore file
but you can supply your list of ignored files as a simple array e.g: var ignored = ['node_modules', '.git', '.vagrant', 'etc.'];

Research

Asynchronous (non-blocking) without Async (the module)

The async (module) is good (as evidenced by its popularity!)
But way too many people use it as a crutch instead of understanding how to write their own asynchronous code.
We have deliberately avoided using async (the module) here, and as a result, listdirs is faster (we benchmarked it!) and includes less bloat.

We have included one dependency on isdir for the sake of splitting out code into "does-only-one-thing" (micro-modules) but isdir has zero dependencies so we know the stack!

Existing Options

As usual, a search on NPM (for list directories) returns many results:

npm-search-list-directories

A few of the modules we looked at before deciding to write our own:

  • nodejs-walker: https://github.com/daaku/nodejs-walker unclear docs.
  • dirtree: https://www.npmjs.com/package/dirtree comes really close to what we want! except it returns a tree object where we want a simple array.
  • dirs: https://github.com/jonschlinkert/dirs unclear docs. uses async (=== lazy).
  • dirlist: https://www.npmjs.com/package/dirlist (is a directory listing server - not a utility module)

Background Reading

Highly recommend reading the Unix Philosophy if you haven't already.

  • 17 Unix Rules: http://en.wikipedia.org/wiki/Unix_philosophy#Eric_Raymond.E2.80.99s_17_Unix_Rules