readDir node code example
Example 1: nodejs readdir
const fs = require("fs")
fs.readdir("./myfolder", (err, data) => {
if(err) throw err
console.log(data)
})
Example 2: fs writefile node
const fs = require('fs')
const content = 'Some content!'
fs.writeFile('/Users/joe/test.txt', content, err => {
if (err) {
console.error(err)
return
}
//file written successfully
})
Example 3: fs readfile encoding
fs.readFile('/etc/passwd', 'utf8', callback);