Skip to content

Instantly share code, notes, and snippets.

@richardoey
Created June 22, 2021 08:50
Show Gist options
  • Save richardoey/3caf14fc34a2757b028b2a5637334d29 to your computer and use it in GitHub Desktop.
Save richardoey/3caf14fc34a2757b028b2a5637334d29 to your computer and use it in GitHub Desktop.
Async/Await with Nodejs File System. Reference: https://dev.to/starpebble/async-await-with-nodejs-file-system-1aa2
async function f() {
const fsPromises = require('fs').promises;
const data = await fsPromises.readFile('/tmp/data.json')
.catch((err) => console.error('Error: ', err));
return JSON.parse(data.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment