📅  最后修改于: 2022-03-11 15:04:33.178000             🧑  作者: Mango
const { read } = require('fs')
const readJsonFile = file => {
if (file.split('.')[file.split('.').length - 1] !== 'json') return {}
const fileContent = read(file)
if (!fileContent) return {}
return JSON.parse(fileContent)
}
readJsonFile('package.json')