Last active
May 20, 2018 18:00
-
-
Save NasirNobin/fcec8dc334dd5644095f4a460645cac4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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