Skip to content

Instantly share code, notes, and snippets.

@kwokhou
Created March 27, 2022 23:43
Show Gist options
  • Save kwokhou/a73ebf163cb4399764291922e10eac90 to your computer and use it in GitHub Desktop.
Save kwokhou/a73ebf163cb4399764291922e10eac90 to your computer and use it in GitHub Desktop.
Read and write file in NodeJS
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