Skip to content

Instantly share code, notes, and snippets.

@bmeck
Created June 15, 2010 14:46
Show Gist options
  • Save bmeck/439216 to your computer and use it in GitHub Desktop.
Save bmeck/439216 to your computer and use it in GitHub Desktop.

npm list [filters]

display list of packages in a format (default is terse)

Filters

Filters take may subfilter with the syntax subfilter=pattern, if you need multiple subfilters separate them by commas, by default all filters must be matched to return a package. For filters on a set of data such as authors the filter only needs to match 1 entry out of the set.

Syntax

String

...|"..."

Pattern

/.../

Comparison

[<>!]?=... Check if comparison matches a semantic variable, else check if it is a number (number compared against date is comparison against number of milliseconds since 1970), else a date, else a string.

Subfilters:

Any filter without a subfilter is considered 'generic'. Generic filters are applied to all aspects of a package. Filters following a subfilter will only be applied to a specific part of a package.

name

package name

Comparison - String

tag

package tag

Comparison - Array of Strings (does not include the '@')

version

package version (non-url)

Comparison - Semantic Variable (1.0.0 etc.)

installed

package installed version (non-url)

Comparison - Semantic Variable (1.0.0 etc.)

stable

package stable version (non-url)

Comparison - Semantic Variable (1.0.0 etc.)

latest

package latest version (non-url)

Comparison - Semantic Variable (1.0.0 etc.)

author

package maintainers (name and email)

Comparison - String on name and email

created

package creation time (in UTC)

Comparison - Date

modified

package modified time (in UTC)

Comparison - Date

description

package description

Comparison - String

extended-options:

--format verbose

extend the display to

----------------------
Package Name
__[maintainers (name - email , ...)]__
- - - - - - - - - - - 
[installed@version] [stable@version] __[latest@version]__
DESCRIPTION:
[description]
TAGS: __[tags]__
VERSIONS: __[versions]__
----------------------

--format terse

trim the display to

Package Name [installed@version] [stable@version]

--format ...

if format did not match a prebuilt format, it will be interpretted by mustache.js syntax rules with the following additions

Slices

Enumerables may now be sliced into sections of themselves while enumerating using '[' x '..' y ']', 0 based, inclusive on both ends. Slices allow access to {{|}} for length and {{@}} for index.

Context

{ name: '', authors: [{name:'',email:''},], versions: {stable:'',installed:['',],latest:'',active:''}, modules: {'x.y.z':{url:''}} description: '' created: Date modified: Date }

--registry local

search only installed packages

--orderby [filter[-reverse]]

orders according to number of times a filter matched (matches of same count will be ordered alphabetically)

[filter]-reverse

reverse the order (ie. name-reverse)

--allow partial

include partial matches (use orderby for having them put at top/bottom)

Example

given a local registry of: { foo: { '1.0.1': { active: true } }

and a remote registry of: { name: 'bar' , description: 'not foo' , 'dist-tags': { latest: '2.2.2', stable: '1.1.1' } , maintainers: [ { name: 'null', email: '[email protected]' } ] , mtime: '2010-01-11T12:00:00Z' , ctime: '2010-01-01T00:00:00Z' , versions: { '0.0.0': 'http://registry.npmjs.org/bar/0.0.0' , '1.1.1': 'http://registry.npmjs.org/bar/1.1.1' , '2.2.2': 'http://registry.npmjs.org/bar/2.2.2' } } { name: 'foo' , description: 'not bar' , 'dist-tags': { latest: '1.2.3', stable: '1.0.1' } , maintainers: [ { name: 'void', email: '[email protected]' }, { name: 'not', email: '[email protected]' } ] , mtime: '2010-01-11T12:00:00Z' , ctime: '2010-01-01T00:00:00Z' , versions: { '0.0.0': 'http://registry.npmjs.org/foo/0.0.0' , '1.0.1': 'http://registry.npmjs.org/foo/1.0.1' , '1.2.3': 'http://registry.npmjs.org/foo/1.2.3' } }

  1. npm ls --local

A simple search of installed packages.

-----------------
foo
- - - - - - - - -
[email protected] [email protected] [email protected]
not bar
-----------------
  1. npm ls --registry local --format verbose

A more verbose search of installed packages.

-----------------
foo
void - [email protected], not - [email protected]
- - - - - - - - -
[email protected] [email protected] [email protected]
DESCRIPTION:
not bar
TAGS: installed, stable
VERSIONS: 0.0.0, 1.0.1
-----------------
  1. npm ls --orderby name-reverse

Reverse the natural order of the packages. Same as --orderby -reverse.

-----------------
foo
- - - - - - - - -
[email protected] [email protected] [email protected]
not bar
-----------------
bar
- - - - - - - - -
[email protected] [email protected]
not foo
-----------------
  1. npm ls version=/^1.\d/ --orderby latest-reverse

This would match any version above 1 and is equivalent to: npm ls -version >=1.0.0, npm ls -version >=1. This matches both and since the lastest version of foo is less than bar, it comes first.

-----------------
foo
- - - - - - - - -
[email protected] [email protected] [email protected]
not bar
-----------------
bar
- - - - - - - - -
[email protected] [email protected]
not foo
-----------------
  1. npm ls --format terse

    foo [email protected] [email protected].

    bar [email protected]

@isaacs
Copy link

isaacs commented Jun 15, 2010

Replied on the list. Thanks!

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