Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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");
- });
- });
Add Comment
Please, Sign In to add comment