Skip to content

Instantly share code, notes, and snippets.

@jessireedev
Created October 1, 2024 08:17
Show Gist options
  • Save jessireedev/7d764a0de4bdfbcfb5eaae1f46622ece to your computer and use it in GitHub Desktop.
Save jessireedev/7d764a0de4bdfbcfb5eaae1f46622ece to your computer and use it in GitHub Desktop.
FS Promises
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