Identify the NPMs used in the running node.js application

Besides capturing the file package.jsonin the root of the project, is there a way to determine the list of dependencies of the running node.js application? Does node provide this meta information as some var in the global namespace?

+5
source share
2 answers

If you are looking only for installed npm packages in the application directory, you can install npm ( npm install -g npm) and programmatically call lsto list installed packages and dependency trees.

Obviously, this does not affect whether the installed packages are actually installed requirein the application or not.

, .

var npm = require('npm');

npm.load(function(err, npm) {
    npm.commands.ls([], true, function(err, data, lite) {
        console.log(data); //or lite for simplified output
    });
});

:.

{ dependencies:
   { npm: { version: '1.1.18', dependencies: [Object] },
     request: { version: '2.9.202' } } }

, module, , / , , API. , - , , , ,

var req = require('request'); // require some module for demo purposes
var m = require('module');

// properties of m contain current loaded module info, e.g. m._cache
+6

, require-analyzer, Isaacs ( ). Nodeup first podcast 11:55.

James node-detective, , , ( ), - Javascript (12:46).

, () , .

P.S: package.json node.js, node -pkginfo

+2

All Articles