Skip to content

Instantly share code, notes, and snippets.

@NasirNobin
Last active May 20, 2018 18:00
Show Gist options
  • Select an option

  • Save NasirNobin/fcec8dc334dd5644095f4a460645cac4 to your computer and use it in GitHub Desktop.

Select an option

Save NasirNobin/fcec8dc334dd5644095f4a460645cac4 to your computer and use it in GitHub Desktop.
fs = require('fs')
const needToPrint = ['name','description','version'];
const needToCopy = needToPrint.concat('dependencies');
const newJson = {};
fs.readFile('package.json', 'utf8', (err,data) => {
if (err) {
return console.log(err);
}
let json = JSON.parse(data);
for(let key in json){
if (needToPrint.indexOf(key) !== -1) {
console.log(key, ':' , json[key]);
}
if (needToCopy.indexOf(key) !== -1) {
newJson[key] = json[key];
}
}
fs.writeFile('data.json', JSON.stringify(newJson), err => {
if(err) {
return console.log(err);
}
console.log("The file was saved as data.json");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment