Created
January 14, 2020 21:15
-
-
Save qunabu/7a84ad0e21e6e7616e14b1fc36b7fcc5 to your computer and use it in GitHub Desktop.
getJSON
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
/** | |
* Get json from local machine | |
* @param {String} filename on local machine | |
* @returns {Promise} resolved object is JSON | |
*/ | |
const getJSON = filename => { | |
return new Promise((resolve, reject) => { | |
fs.readFile(filename, (err, data) => { | |
if (err) { | |
reject(err); | |
} | |
try { | |
resolve(JSON.parse(data)); | |
} catch (err) { | |
reject(err); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment