Problem Statement
How do you open a file in Node.js?
Explanation
Use the `fs.open()` method to open a file. It takes a filename, flag (like 'r' for read or 'w' for write), and a callback. Always handle errors to avoid crashes.
Code Solution
SolutionRead Only
const fs = require('fs');
fs.open('example.txt', 'r', (err, fd) => {
if (err) throw err;
console.log('File opened successfully');
});