Complete the code to import the file system module.
const fs = require([1]);The fs module is imported using require("fs") to access file system functions.
Complete the code to read a file asynchronously with a callback.
fs.readFile('example.txt', 'utf8', [1]);
The callback function receives error and data arguments. It handles errors and logs the file content.
Fix the error in the callback function to properly handle errors.
fs.readFile('data.txt', 'utf8', ([1], content) => { if ([1]) throw [1]; console.log(content); });
The first parameter in the callback is commonly named err. The code must check err, not error.
Fill both blanks to read a file and handle errors properly.
fs.readFile('log.txt', [1], ([2], data) => { if (err) throw err; console.log(data); });
The encoding should be 'utf8' to read text properly. The error parameter is commonly named err and must match the check.
Fill all three blanks to read a file asynchronously and log errors or data.
fs.readFile([1], [2], ([3], content) => { if (err) console.error(err); else console.log(content); });
The file name is 'notes.txt', encoding is 'utf8', and the error parameter is named err to handle errors properly.