1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| const fs =require('fs')
function readFileAsync(path){ return new Promise((resolve,reject)=>{ fs.readFile(path,(err,data)=>{ if(err) reject(err) else resolve(data) }) }) } readFileAsync('./package.json').then(data=>{ data=JSON.parse(data) console.log(data.name) }).catch(err=>{ console.log(err) })
|