Skip to content

Instantly share code, notes, and snippets.

@CiceroLino
Forked from sethdavis512/readAndWrite.tsx
Created September 1, 2023 15:22
Show Gist options
  • Save CiceroLino/881d789d2336e3412ffe4e3e07239ed9 to your computer and use it in GitHub Desktop.
Save CiceroLino/881d789d2336e3412ffe4e3e07239ed9 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