Last active
November 13, 2024 15:36
-
-
Save sethdavis512/4d8eba44076fc85fd81aa9f4d7035e28 to your computer and use it in GitHub Desktop.
Node read and write async functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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