Skip to content

Instantly share code, notes, and snippets.

@aaronpowell
Created February 21, 2012 05:41
Show Gist options
  • Select an option

  • Save aaronpowell/1874007 to your computer and use it in GitHub Desktop.

Select an option

Save aaronpowell/1874007 to your computer and use it in GitHub Desktop.
Read packages
var fs = require('fs');
var packages = [];
var readPackage = function (file) {
if (file === '.bin') {
return;
}
var pkg;
var stat = fs.statSync(__dirname + '/node_modules/' + file);
if (stat.isDirectory()) {
pkg = require(file + '/package');
packages.push({
name: pkg.name,
version: pkg.version
});
}
};
var files = fs.readdirSync('node_modules');
for (var i = 0, il = files.length; i < il; i++) {
readPackage(files[i]);
}
console.log(packages);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment