Skip to content

Instantly share code, notes, and snippets.

@jingyuexing
Created November 11, 2019 21:19
Show Gist options
  • Save jingyuexing/45f4d8a14f0fdee9f95cbfceb642c76e to your computer and use it in GitHub Desktop.
Save jingyuexing/45f4d8a14f0fdee9f95cbfceb642c76e to your computer and use it in GitHub Desktop.
Read JSON file in nodejs
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