Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created September 11, 2020 21:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sethdavis512/4d8eba44076fc85fd81aa9f4d7035e28 to your computer and use it in GitHub Desktop.
Save sethdavis512/4d8eba44076fc85fd81aa9f4d7035e28 to your computer and use it in GitHub Desktop.
Node read and write async functions
const read = async (filePath: string) => {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', (err: any, data: string) => {
if (err) reject(err)
resolve(data)
})
})
}
const write = (filePath: string, fileName: string, fileExtension: string, content: any) => {
return new Promise((resolve, reject) => {
fs.writeFile(`${filePath}/${fileName}.${fileExtension}`, content, (err: any) => {
if (err) reject(err)
console.log('\n💥SUCCESS\n')
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment