Skip to content

Instantly share code, notes, and snippets.

@shanestillwell
Created March 22, 2013 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanestillwell/5218735 to your computer and use it in GitHub Desktop.
Save shanestillwell/5218735 to your computer and use it in GitHub Desktop.
Query your node_modules to build a list for packages.json
var fs = require("fs");
function main() {
fs.readdir("./node_modules", function (err, dirs) {
if (err) {
console.log(err);
return;
}
dirs.forEach(function(dir){
if (dir.indexOf(".") !== 0) {
var packageJsonFile = "./node_modules/" + dir + "/package.json";
if (fs.existsSync(packageJsonFile)) {
fs.readFile(packageJsonFile, function (err, data) {
if (err) {
console.log(err);
}
else {
var json = JSON.parse(data);
console.log('"'+json.name+'": "' + json.version + '",');
}
});
}
}
});
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment