Get the dependency chain for a specified Node module (or a collection of modules). Think of it as a remote
getDepChain(package[s], options, callback), where:
- the first param is either an object with the properties 'name' and 'version', or a collection of such objects
- options is an object that can have 2 properties: 'filter', a function that will filter packages (see examples below) and 'npmClient' (an instance of npm-pkginfo in case you want to provide your custom cache store or specify a custom NPM registry URL)
- custom replication of the NPM registry (only replicate the modules you want)
- statistics / analysis based on the modules used by your application, like finding out all the licences of the dependency chain or listing all the authors of them
npm lslike command, but without having the dependencies installed locally
/*** Get all dependencies for multiple versions of Express and NPM latest*/var getDepChain = util = ; ;
using a filter function:
var getDepChain = util = ; ;
Look in the /examples folder, there are more complex examples there.
I wanted to create my private NPM registry with custom replication, so I needed to know the dependency tree for a module in order to replicate it (along with all its subdependencies) to that private registry.
How does it work?
It goes to the NPM registry to get a module's dependencies (or even for more modules), then repeats the dependencies found and so on. It uses a cache (by default stored in __dirname + '/cache') so that if you get the info for a module it won't go to the registry a second time for the same module (but in case there is no compatible version found for the module based on the cached info, it will refresh the cache). For more info, checkout npm-pkginfo, which is used internally.