Created
August 29, 2022 00:08
-
-
Save kwokhou/9eca515ab07d848bbcfd525c1c91ad3b to your computer and use it in GitHub Desktop.
Reading and writing to file in NodeJS
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 fs = require('fs'); | |
const readFile = async filePath => { | |
try { | |
const data = await fs.promises.readFile(filePath, 'utf8') | |
return data | |
} | |
catch(err) { | |
console.log(err) | |
} | |
} | |
const writeFile = async (filePath, fileContent) => { | |
try { | |
await fs.promises.writeFile(filePath, fileContent) | |
} | |
catch(err) { | |
console.log(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment