Skip to content

Instantly share code, notes, and snippets.

@neilhawkins
Created January 11, 2015 17:22
Show Gist options
  • Save neilhawkins/b3f16104a0565529357f to your computer and use it in GitHub Desktop.
Save neilhawkins/b3f16104a0565529357f to your computer and use it in GitHub Desktop.
reads a node modules directory and outputs all packages and versions for when you forget to --save-dev...
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