Skip to content

Instantly share code, notes, and snippets.

@qunabu
Created January 14, 2020 21:15
Show Gist options
  • Save qunabu/7a84ad0e21e6e7616e14b1fc36b7fcc5 to your computer and use it in GitHub Desktop.
Save qunabu/7a84ad0e21e6e7616e14b1fc36b7fcc5 to your computer and use it in GitHub Desktop.
getJSON
/**
* 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