Skip to content

Instantly share code, notes, and snippets.

@nicholascloud
Last active December 16, 2015 03:49
Show Gist options
  • Save nicholascloud/5372443 to your computer and use it in GitHub Desktop.
Save nicholascloud/5372443 to your computer and use it in GitHub Desktop.
blog-npm-root-packages

The problem

When I list my npm packages with npm ls -g (or without the -g option for a local node_modules directory) I see all installed packages and their dependencies. Like so:

$ npm ls -g
β”œβ”€β”¬ anvil.js@0.9.0-RC3.1
β”‚ β”œβ”€β”€ colors@0.6.0
β”‚ β”œβ”€β”¬ commander@1.1.1
β”‚ β”‚ └── keypress@0.1.0
β”‚ β”œβ”€β”¬ express@3.0.5
β”‚ β”‚ β”œβ”€β”€ buffer-crc32@0.1.1
β”‚ β”‚ β”œβ”€β”€ commander@0.6.1
β”‚ β”‚ β”œβ”€β”¬ connect@2.7.1
β”‚ β”‚ β”‚ β”œβ”€β”€ bytes@0.1.0
β”‚ β”‚ β”‚ β”œβ”€β”€ crc@0.2.0
β”‚ β”‚ β”‚ β”œβ”€β”€ formidable@1.0.11
β”‚ β”‚ β”‚ β”œβ”€β”€ pause@0.0.1
β”‚ β”‚ β”‚ └── qs@0.5.1
β”‚ β”‚ β”œβ”€β”€ cookie@0.0.5
β”‚ β”‚ β”œβ”€β”€ cookie-signature@0.0.1
β”‚ β”‚ β”œβ”€β”€ debug@0.7.0
β”‚ β”‚ β”œβ”€β”€ fresh@0.1.0
β”‚ β”‚ β”œβ”€β”€ methods@0.0.1
β”‚ β”‚ β”œβ”€β”€ range-parser@0.0.4
β”‚ β”‚ └─┬ send@0.1.0
β”‚ β”‚   └── mime@1.2.6
β”‚ β”œβ”€β”¬ fs-watch-tree@0.2.2
β”‚ β”‚ └── when@1.3.0
β”‚ β”œβ”€β”¬ handlebars@1.0.7
β”‚ β”‚ β”œβ”€β”¬ optimist@0.3.5
β”‚ β”‚ β”‚ └── wordwrap@0.0.2
β”‚ β”‚ └── uglify-js@1.2.6
β”‚ β”œβ”€β”€ machina@0.2.2
β”‚ β”œβ”€β”¬ minimatch@0.2.9
β”‚ β”‚ β”œβ”€β”€ lru-cache@2.0.4
β”‚ β”‚ └── sigmund@1.0.0
β”‚ β”œβ”€β”€ mkdirp@0.3.3
β”‚ β”œβ”€β”€ open@0.0.2
β”‚ β”œβ”€β”€ postal@0.7.3
β”‚ β”œβ”€β”€ should@0.6.3
β”‚ β”œβ”€β”¬ socket.io@0.9.13
β”‚ β”‚ β”œβ”€β”€ base64id@0.1.0
β”‚ β”‚ β”œβ”€β”€ policyfile@0.0.4
β”‚ β”‚ β”œβ”€β”€ redis@0.7.3
β”‚ β”‚ └─┬ socket.io-client@0.9.11
β”‚ β”‚   β”œβ”€β”¬ active-x-obfuscator@0.0.1
β”‚ β”‚   β”‚ └── zeparser@0.0.5
β”‚ β”‚   β”œβ”€β”€ uglify-js@1.2.5
β”‚ β”‚   β”œβ”€β”¬ ws@0.4.25
β”‚ β”‚   β”‚ β”œβ”€β”€ commander@0.6.1
β”‚ β”‚   β”‚ β”œβ”€β”€ options@0.0.3
β”‚ β”‚   β”‚ └── tinycolor@0.0.1
β”‚ β”‚   └── xmlhttprequest@1.4.2
β”‚ └── underscore@1.4.3
β”œβ”€β”¬ grunt@0.3.17
β”‚ β”œβ”€β”€ async@0.1.22
β”‚ β”œβ”€β”€ colors@0.6.0-1
β”‚ β”œβ”€β”¬ connect@2.4.6
β”‚ β”‚ β”œβ”€β”€ bytes@0.1.0
β”‚ β”‚ β”œβ”€β”€ cookie@0.0.4
β”‚ β”‚ β”œβ”€β”€ crc@0.2.0
β”‚ β”‚ β”œβ”€β”€ debug@0.7.0
β”‚ β”‚ β”œβ”€β”€ formidable@1.0.11
β”‚ β”‚ β”œβ”€β”€ fresh@0.1.0
β”‚ β”‚ β”œβ”€β”€ pause@0.0.1
β”‚ β”‚ β”œβ”€β”€ qs@0.5.1
β”‚ β”‚ └─┬ send@0.0.4
β”‚ β”‚   β”œβ”€β”€ mime@1.2.6
β”‚ β”‚   └── range-parser@0.0.4
β”‚ β”œβ”€β”€ dateformat@1.0.2-1.2.3
β”‚ β”œβ”€β”¬ glob-whatev@0.1.8
β”‚ β”‚ └─┬ minimatch@0.2.9
β”‚ β”‚   β”œβ”€β”€ lru-cache@2.0.4
β”‚ β”‚   └── sigmund@1.0.0
β”‚ β”œβ”€β”¬ gzip-js@0.3.1
β”‚ β”‚ β”œβ”€β”€ crc32@0.2.2
β”‚ β”‚ └── deflate-js@0.2.2
β”‚ β”œβ”€β”€ hooker@0.2.3
β”‚ β”œβ”€β”¬ jshint@0.9.1
β”‚ β”‚ β”œβ”€β”¬ cli@0.4.3
β”‚ β”‚ β”‚ └─┬ glob@3.1.14
β”‚ β”‚ β”‚   β”œβ”€β”€ graceful-fs@1.1.14
β”‚ β”‚ β”‚   β”œβ”€β”€ inherits@1.0.0
β”‚ β”‚ β”‚   └─┬ minimatch@0.2.9
β”‚ β”‚ β”‚     β”œβ”€β”€ lru-cache@2.0.4
β”‚ β”‚ β”‚     └── sigmund@1.0.0
β”‚ β”‚ └─┬ minimatch@0.0.5
β”‚ β”‚   └── lru-cache@1.0.6
β”‚ β”œβ”€β”¬ nodeunit@0.7.4
β”‚ β”‚ └─┬ tap@0.3.2
β”‚ β”‚   β”œβ”€β”€ buffer-equal@0.0.0
β”‚ β”‚   β”œβ”€β”€ deep-equal@0.0.0
β”‚ β”‚   β”œβ”€β”¬ difflet@0.2.3
β”‚ β”‚   β”‚ β”œβ”€β”€ charm@0.0.8
β”‚ β”‚   β”‚ └── traverse@0.6.3
β”‚ β”‚   β”œβ”€β”€ inherits@1.0.0
β”‚ β”‚   β”œβ”€β”€ mkdirp@0.3.4
β”‚ β”‚   β”œβ”€β”¬ nopt@2.0.0
β”‚ β”‚   β”‚ └── abbrev@1.0.3
β”‚ β”‚   β”œβ”€β”¬ runforcover@0.0.2
β”‚ β”‚   β”‚ └─┬ bunker@0.1.2
β”‚ β”‚   β”‚   └─┬ burrito@0.2.12
β”‚ β”‚   β”‚     β”œβ”€β”€ traverse@0.5.2
β”‚ β”‚   β”‚     └── uglify-js@1.1.1
β”‚ β”‚   β”œβ”€β”€ slide@1.1.3
β”‚ β”‚   └── yamlish@0.0.5
β”‚ β”œβ”€β”¬ nopt@1.0.10
β”‚ β”‚ └── abbrev@1.0.3
β”‚ β”œβ”€β”¬ prompt@0.1.12
β”‚ β”‚ β”œβ”€β”€ pkginfo@0.2.3
β”‚ β”‚ └─┬ winston@0.5.11
β”‚ β”‚   β”œβ”€β”€ eyes@0.1.8
β”‚ β”‚   β”œβ”€β”¬ loggly@0.3.11
β”‚ β”‚   β”‚ β”œβ”€β”€ request@2.9.203
β”‚ β”‚   β”‚ └── timespan@2.2.0
β”‚ β”‚   └── stack-trace@0.0.6
β”‚ β”œβ”€β”€ semver@1.0.14
β”‚ β”œβ”€β”¬ temporary@0.0.5
β”‚ β”‚ └── package@1.0.1
β”‚ β”œβ”€β”€ uglify-js@1.3.4
β”‚ β”œβ”€β”€ underscore@1.2.4
β”‚ └── underscore.string@2.1.1
β”œβ”€β”¬ jake@0.5.8
β”‚ β”œβ”€β”¬ minimatch@0.2.9
β”‚ β”‚ β”œβ”€β”€ lru-cache@2.0.4
β”‚ β”‚ └── sigmund@1.0.0
β”‚ └── utilities@0.0.19
β”œβ”€β”¬ jitsu@0.11.4
β”‚ β”œβ”€β”€ colors@0.6.0-1
β”‚ β”œβ”€β”€ complete@0.3.1
β”‚ β”œβ”€β”€ dateformat@1.0.2-1.2.3
β”‚ β”œβ”€β”¬ flatiron@0.3.0
β”‚ β”‚ β”œβ”€β”¬ broadway@0.2.5
β”‚ β”‚ β”‚ β”œβ”€β”¬ cliff@0.1.8
β”‚ β”‚ β”‚ β”‚ └── eyes@0.1.8
β”‚ β”‚ β”‚ β”œβ”€β”€ eventemitter2@0.4.9
β”‚ β”‚ β”‚ β”œβ”€β”¬ nconf@0.6.4
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ async@0.1.22
β”‚ β”‚ β”‚ β”‚ └── ini@1.0.5
β”‚ β”‚ β”‚ β”œβ”€β”¬ utile@0.1.2
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ async@0.1.22
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ deep-equal@0.0.0
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ i@0.3.1
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ mkdirp@0.3.4
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ ncp@0.2.6
β”‚ β”‚ β”‚ β”‚ └── rimraf@1.0.9
β”‚ β”‚ β”‚ └─┬ winston@0.6.2
β”‚ β”‚ β”‚   β”œβ”€β”€ async@0.1.22
β”‚ β”‚ β”‚   β”œβ”€β”€ cycle@1.0.1
β”‚ β”‚ β”‚   β”œβ”€β”€ eyes@0.1.8
β”‚ β”‚ β”‚   └── stack-trace@0.0.6
β”‚ β”‚ β”œβ”€β”€ director@1.1.6
β”‚ β”‚ β”œβ”€β”¬ optimist@0.3.4
β”‚ β”‚ β”‚ └── wordwrap@0.0.2
β”‚ β”‚ └─┬ prompt@0.2.8
β”‚ β”‚   β”œβ”€β”¬ read@1.0.4
β”‚ β”‚   β”‚ └── mute-stream@0.0.3
β”‚ β”‚   β”œβ”€β”€ revalidator@0.1.5
β”‚ β”‚   β”œβ”€β”¬ utile@0.1.6
β”‚ β”‚   β”‚ β”œβ”€β”€ async@0.1.22
β”‚ β”‚   β”‚ β”œβ”€β”€ deep-equal@0.0.0
β”‚ β”‚   β”‚ β”œβ”€β”€ i@0.3.1
β”‚ β”‚   β”‚ β”œβ”€β”€ mkdirp@0.3.4
β”‚ β”‚   β”‚ β”œβ”€β”€ ncp@0.2.6
β”‚ β”‚   β”‚ └── rimraf@1.0.9
β”‚ β”‚   └─┬ winston@0.6.2
β”‚ β”‚     β”œβ”€β”€ async@0.1.22
β”‚ β”‚     β”œβ”€β”€ cycle@1.0.1
β”‚ β”‚     β”œβ”€β”€ eyes@0.1.8
β”‚ β”‚     └── stack-trace@0.0.6
β”‚ β”œβ”€β”€ flatiron-cli-config@0.1.3
β”‚ β”œβ”€β”€ flatiron-cli-users@0.1.1
β”‚ β”œβ”€β”¬ fstream@0.1.18
β”‚ β”‚ β”œβ”€β”€ graceful-fs@1.1.14
β”‚ β”‚ β”œβ”€β”€ inherits@1.0.0
β”‚ β”‚ β”œβ”€β”€ mkdirp@0.3.4
β”‚ β”‚ └── rimraf@2.1.1
β”‚ β”œβ”€β”¬ fstream-npm@0.1.1
β”‚ β”‚ β”œβ”€β”¬ fstream-ignore@0.0.5
β”‚ β”‚ β”‚ └─┬ minimatch@0.2.9
β”‚ β”‚ β”‚   β”œβ”€β”€ lru-cache@2.0.4
β”‚ β”‚ β”‚   └── sigmund@1.0.0
β”‚ β”‚ └── inherits@1.0.0
β”‚ β”œβ”€β”€ ladder@0.0.0
β”‚ β”œβ”€β”€ nodejitsu-api@0.3.6
β”‚ β”œβ”€β”¬ npm@1.1.59
β”‚ β”‚ β”œβ”€β”€ abbrev@1.0.3
β”‚ β”‚ β”œβ”€β”€ ansi@0.1.2
β”‚ β”‚ β”œβ”€β”€ archy@0.0.2
β”‚ β”‚ β”œβ”€β”€ block-stream@0.0.6
β”‚ β”‚ β”œβ”€β”€ chownr@0.0.1
β”‚ β”‚ β”œβ”€β”€ couch-login@0.1.10
β”‚ β”‚ β”œβ”€β”€ fstream@0.1.18
β”‚ β”‚ β”œβ”€β”¬ fstream-npm@0.1.1
β”‚ β”‚ β”‚ └── fstream-ignore@0.0.5
β”‚ β”‚ β”œβ”€β”€ glob@3.1.12
β”‚ β”‚ β”œβ”€β”€ graceful-fs@1.1.10
β”‚ β”‚ β”œβ”€β”€ inherits@1.0.0
β”‚ β”‚ β”œβ”€β”€ ini@1.0.4
β”‚ β”‚ β”œβ”€β”¬ init-package-json@0.0.5
β”‚ β”‚ β”‚ └── promzard@0.2.0
β”‚ β”‚ β”œβ”€β”€ lockfile@0.2.1
β”‚ β”‚ β”œβ”€β”€ lru-cache@2.0.1
β”‚ β”‚ β”œβ”€β”€ minimatch@0.2.6
β”‚ β”‚ β”œβ”€β”€ mkdirp@0.3.4
β”‚ β”‚ β”œβ”€β”€ node-gyp@0.6.7
β”‚ β”‚ β”œβ”€β”€ nopt@2.0.0
β”‚ β”‚ β”œβ”€β”€ npm-registry-client@0.2.6
β”‚ β”‚ β”œβ”€β”¬ npmconf@0.0.11
β”‚ β”‚ β”‚ └─┬ config-chain@1.1.1
β”‚ β”‚ β”‚   └── proto-list@1.2.2
β”‚ β”‚ β”œβ”€β”€ npmlog@0.0.2
β”‚ β”‚ β”œβ”€β”€ once@1.1.1
β”‚ β”‚ β”œβ”€β”€ osenv@0.0.3
β”‚ β”‚ β”œβ”€β”¬ read@1.0.4
β”‚ β”‚ β”‚ └── mute-stream@0.0.3
β”‚ β”‚ β”œβ”€β”€ read-installed@0.0.2
β”‚ β”‚ β”œβ”€β”€ read-package-json@0.1.4
β”‚ β”‚ β”œβ”€β”€ request@2.9.203
β”‚ β”‚ β”œβ”€β”€ retry@0.6.0
β”‚ β”‚ β”œβ”€β”€ rimraf@2.0.2
β”‚ β”‚ β”œβ”€β”€ semver@1.0.14
β”‚ β”‚ β”œβ”€β”€ slide@1.1.3
β”‚ β”‚ β”œβ”€β”€ tar@0.1.13
β”‚ β”‚ β”œβ”€β”€ uid-number@0.0.3
β”‚ β”‚ └── which@1.0.5
β”‚ β”œβ”€β”€ opener@1.3.0
β”‚ β”œβ”€β”€ pkginfo@0.2.3
β”‚ β”œβ”€β”€ progress@0.1.0
β”‚ β”œβ”€β”€ request@2.9.203
β”‚ β”œβ”€β”¬ require-analyzer@0.4.0-3
β”‚ β”‚ β”œβ”€β”¬ detective@0.0.4
β”‚ β”‚ β”‚ └─┬ burrito@0.2.12
β”‚ β”‚ β”‚   β”œβ”€β”€ traverse@0.5.2
β”‚ β”‚ β”‚   └── uglify-js@1.1.1
β”‚ β”‚ β”œβ”€β”€ eyes@0.1.8
β”‚ β”‚ β”œβ”€β”¬ findit@0.0.5
β”‚ β”‚ β”‚ └─┬ seq@0.3.5
β”‚ β”‚ β”‚   β”œβ”€β”¬ chainsaw@0.0.9
β”‚ β”‚ β”‚   β”‚ └── traverse@0.3.9
β”‚ β”‚ β”‚   └─┬ hashish@0.0.4
β”‚ β”‚ β”‚     └── traverse@0.6.3
β”‚ β”‚ β”œβ”€β”¬ npm@1.1.4
β”‚ β”‚ β”‚ β”œβ”€β”€ abbrev@1.0.3
β”‚ β”‚ β”‚ β”œβ”€β”€ block-stream@0.0.5
β”‚ β”‚ β”‚ β”œβ”€β”€ fast-list@1.0.2
β”‚ β”‚ β”‚ β”œβ”€β”€ fstream@0.1.12
β”‚ β”‚ β”‚ β”œβ”€β”€ graceful-fs@1.1.5
β”‚ β”‚ β”‚ β”œβ”€β”€ inherits@1.0.0
β”‚ β”‚ β”‚ β”œβ”€β”€ ini@1.0.2
β”‚ β”‚ β”‚ β”œβ”€β”€ lru-cache@1.0.5
β”‚ β”‚ β”‚ β”œβ”€β”€ minimatch@0.1.5
β”‚ β”‚ β”‚ β”œβ”€β”€ mkdirp@0.3.0
β”‚ β”‚ β”‚ β”œβ”€β”€ node-uuid@1.3.3
β”‚ β”‚ β”‚ β”œβ”€β”€ nopt@1.0.10
β”‚ β”‚ β”‚ β”œβ”€β”€ proto-list@1.0.0
β”‚ β”‚ β”‚ β”œβ”€β”€ read@0.0.1
β”‚ β”‚ β”‚ β”œβ”€β”€ request@2.9.153
β”‚ β”‚ β”‚ β”œβ”€β”€ rimraf@2.0.1
β”‚ β”‚ β”‚ β”œβ”€β”€ semver@1.0.13
β”‚ β”‚ β”‚ β”œβ”€β”€ slide@1.1.3
β”‚ β”‚ β”‚ β”œβ”€β”€ tar@0.1.12
β”‚ β”‚ β”‚ └── which@1.0.5
β”‚ β”‚ β”œβ”€β”¬ optimist@0.2.8
β”‚ β”‚ β”‚ └── wordwrap@0.0.2
β”‚ β”‚ └─┬ winston@0.5.11
β”‚ β”‚   β”œβ”€β”€ async@0.1.22
β”‚ β”‚   β”œβ”€β”¬ loggly@0.3.11
β”‚ β”‚   β”‚ └── timespan@2.2.0
β”‚ β”‚   └── stack-trace@0.0.6
β”‚ β”œβ”€β”€ semver@1.0.14
β”‚ β”œβ”€β”€ spawn-command@0.0.2
β”‚ β”œβ”€β”¬ tar@0.1.13
β”‚ β”‚ β”œβ”€β”€ block-stream@0.0.6
β”‚ β”‚ └── inherits@1.0.0
β”‚ └─┬ wizard@0.0.1
β”‚   └─┬ prompt@0.2.9
β”‚     β”œβ”€β”¬ read@1.0.4
β”‚     β”‚ └── mute-stream@0.0.3
β”‚     β”œβ”€β”€ revalidator@0.1.5
β”‚     β”œβ”€β”¬ utile@0.1.6
β”‚     β”‚ β”œβ”€β”€ async@0.1.22
β”‚     β”‚ β”œβ”€β”€ deep-equal@0.0.0
β”‚     β”‚ β”œβ”€β”€ i@0.3.1
β”‚     β”‚ β”œβ”€β”€ mkdirp@0.3.4
β”‚     β”‚ β”œβ”€β”€ ncp@0.2.6
β”‚     β”‚ └── rimraf@1.0.9
β”‚     └─┬ winston@0.6.2
β”‚       β”œβ”€β”€ async@0.1.22
β”‚       β”œβ”€β”€ cycle@1.0.1
β”‚       β”œβ”€β”€ eyes@0.1.8
β”‚       └── stack-trace@0.0.6
β”œβ”€β”¬ jshint@0.9.1
β”‚ β”œβ”€β”¬ cli@0.4.3
β”‚ β”‚ └─┬ glob@3.1.14
β”‚ β”‚   β”œβ”€β”€ graceful-fs@1.1.14
β”‚ β”‚   β”œβ”€β”€ inherits@1.0.0
β”‚ β”‚   └─┬ minimatch@0.2.9
β”‚ β”‚     β”œβ”€β”€ lru-cache@2.0.4
β”‚ β”‚     └── sigmund@1.0.0
β”‚ └─┬ minimatch@0.0.5
β”‚   └── lru-cache@1.0.6
β”œβ”€β”¬ npm@1.1.65
β”‚ β”œβ”€β”€ abbrev@1.0.3
β”‚ β”œβ”€β”€ ansi@0.1.2
β”‚ β”œβ”€β”€ archy@0.0.2
β”‚ β”œβ”€β”€ block-stream@0.0.6
β”‚ β”œβ”€β”€ chownr@0.0.1
β”‚ β”œβ”€β”€ fstream@0.1.19
β”‚ β”œβ”€β”¬ fstream-npm@0.1.3
β”‚ β”‚ └── fstream-ignore@0.0.5
β”‚ β”œβ”€β”€ glob@3.1.14
β”‚ β”œβ”€β”€ graceful-fs@1.1.14
β”‚ β”œβ”€β”€ inherits@1.0.0
β”‚ β”œβ”€β”€ ini@1.0.5
β”‚ β”œβ”€β”¬ init-package-json@0.0.6
β”‚ β”‚ └── promzard@0.2.0
β”‚ β”œβ”€β”€ lockfile@0.2.1
β”‚ β”œβ”€β”€ lru-cache@2.0.4
β”‚ β”œβ”€β”€ minimatch@0.2.8
β”‚ β”œβ”€β”€ mkdirp@0.3.4
β”‚ β”œβ”€β”€ node-gyp@0.7.1
β”‚ β”œβ”€β”€ nopt@2.0.0
β”‚ β”œβ”€β”¬ npm-registry-client@0.2.10
β”‚ β”‚ └── couch-login@0.1.15
β”‚ β”œβ”€β”¬ npmconf@0.0.16
β”‚ β”‚ └─┬ config-chain@1.1.2
β”‚ β”‚   └── proto-list@1.2.2
β”‚ β”œβ”€β”€ npmlog@0.0.2
β”‚ β”œβ”€β”€ once@1.1.1
β”‚ β”œβ”€β”€ opener@1.3.0
β”‚ β”œβ”€β”€ osenv@0.0.3
β”‚ β”œβ”€β”¬ read@1.0.4
β”‚ β”‚ └── mute-stream@0.0.3
β”‚ β”œβ”€β”€ read-installed@0.0.3
β”‚ β”œβ”€β”€ read-package-json@0.1.8
β”‚ β”œβ”€β”€ request@2.9.203
β”‚ β”œβ”€β”€ retry@0.6.0
β”‚ β”œβ”€β”€ rimraf@2.0.2
β”‚ β”œβ”€β”€ semver@1.1.0
β”‚ β”œβ”€β”€ slide@1.1.3
β”‚ β”œβ”€β”€ tar@0.1.13
β”‚ β”œβ”€β”€ uid-number@0.0.3
β”‚ └── which@1.0.5
β”œβ”€β”¬ phantomjs@0.2.2
β”‚ β”œβ”€β”¬ rimraf@2.0.2
β”‚ β”‚ └── graceful-fs@1.1.14
β”‚ └─┬ unzip@0.0.4
β”‚   β”œβ”€β”¬ binary@0.3.0
β”‚   β”‚ β”œβ”€β”€ buffers@0.1.1
β”‚   β”‚ └─┬ chainsaw@0.1.0
β”‚   β”‚   └── traverse@0.3.9
β”‚   β”œβ”€β”¬ fstream@0.1.19
β”‚   β”‚ β”œβ”€β”€ graceful-fs@1.1.14
β”‚   β”‚ β”œβ”€β”€ inherits@1.0.0
β”‚   β”‚ └── mkdirp@0.3.4
β”‚   └─┬ pullstream@0.0.4
β”‚     β”œβ”€β”€ over@0.0.5
β”‚     └── stream-buffers@0.2.3
└─┬ stylus@0.30.1
  β”œβ”€β”€ cssom@0.2.5
  β”œβ”€β”€ debug@0.7.0
  └── mkdirp@0.3.4

Ugly, yes? I am typically not interested in the dependencies, only top-level packages. I searched the npm man page for a way to filter this ungainly output but alas, I was denied. Or too dumb to see what was right in front of me. In either case, I was left with my problem.

The solution

I added the following snippet to my ~/.bash_profile file:

function npmls() {
  npm ls "$@" | grep ^[β””β”œ]
}

To make the change effective, I sourced the file:

$ source ~/.bash_profile

Now, when I execute the npmls function (to which I can pass standard npm arguments), it will filter the output to show only top-level packages.

$ npmls -g
β”œβ”€β”¬ anvil.js@0.9.0-RC3.1
β”œβ”€β”¬ grunt@0.3.17
β”œβ”€β”¬ jake@0.5.8
β”œβ”€β”¬ jitsu@0.11.4
β”œβ”€β”¬ jshint@0.9.1
β”œβ”€β”¬ npm@1.1.65
β”œβ”€β”¬ phantomjs@0.2.2
└─┬ stylus@0.30.1

Ah, much better. I can put the eye bleach back under the sink now.

@samtsai
Copy link

samtsai commented Feb 28, 2014

Anyone else having issues with the depth flag recently? I feel like with one of the latest updates, 'depth' doesn't do anything...

@matthewrankin
Copy link

@samtsai Yes, the depth doesn't appear to be working in npm v1.4.3 and v1.4.4. As a workaround, you could install npmlist.

@tmugford
Copy link

tmugford commented May 7, 2014

Apparently the --depth issue was fixed as of v1.4.6.. I've updated to v1.4.10 and it's definitely working again for me. So, to recap, you can get a list of globally installed packages minus their dependencies using npm list -g --depth 0.

@bojoer
Copy link

bojoer commented Jun 6, 2014

The correct wa yto get the global installed npm packages without their dependencies is now:

npm list -g --depth=0

@bburns
Copy link

bburns commented Jul 28, 2014

I was on npm 1.4.3 on Windows, tried npm update -g npm, which didn't do anything - it's apparently another issue (see npm/npm#1840).

So just install the latest version of node, which includes npm - mine is up to 1.4.14 now, and --depth works.

Also, you can set 0 as the default with npm set depth 0 (can add -g to store it as your global setting), then just do npm list -g. You can override it with npm list -g --depth 1, etc.

(and both --depth 1 and --depth=1 seem to work alright for this version)

@cweekly
Copy link

cweekly commented Sep 4, 2014

Thanks @tmugford! :)

@gnrlbzik
Copy link

thanks @qjcg

@scott-joe
Copy link

npm list -g --depth 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment