Created
November 11, 2019 21:19
-
-
Save jingyuexing/45f4d8a14f0fdee9f95cbfceb642c76e to your computer and use it in GitHub Desktop.
Read JSON file in nodejs
This file contains 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
const fs = require("fs") | |
function ReadJSON(fileName=''){ | |
var strList = fileName.split("."); | |
var string; | |
if(strList[strList.length-1].toLowerCase()=="json"){ | |
string = fs.readFileSync(fileName); | |
} | |
return JSON.parse(string.toString()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment