10 questions · Node.js · beginner level
What is the difference between fs.readFile() and fs.readFileSync()?
This should read a file and log its content. Spot the bug:
const fs = require("fs")
fs.readFile("data.txt", (data, err) => {
if (err) throw err
console.log(data.toString())
})Which encoding should you pass to get a string instead of a Buffer?
fs.readFile("file.txt", "_______", (err, data) => {
console.log(data) // string, not Buffer
})