Created
October 1, 2024 08:17
-
-
Save jessireedev/7d764a0de4bdfbcfb5eaae1f46622ece to your computer and use it in GitHub Desktop.
FS Promises
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 readFile = async (filePath: string): Promise<string> => { | |
try { | |
const data = await fs.promises.readFile(filePath, 'utf8'); | |
return data; | |
} catch (err) { | |
console.log(err); | |
return ''; | |
} | |
}; | |
const writeFile = async (content: string, filePath: string): Promise<void> => { | |
try { | |
await fs.promises.writeFile(filePath, content); | |
console.log(`Saved at: ${filePath}`); | |
} catch (err) { | |
console.log(err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment