Skip to content

Instantly share code, notes, and snippets.

@mmarchini
Created August 10, 2020 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmarchini/4ac99be21eddcd56934717faee0be433 to your computer and use it in GitHub Desktop.
Save mmarchini/4ac99be21eddcd56934717faee0be433 to your computer and use it in GitHub Desktop.
async-readFile.js
// async function version
const { readFile } = require('fs').promises;
async function readJsonFile(file) {
// Promise is rejected if fails to read or if unexpected JSON input.
return JSON.parse(await readFile(file));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment