Jul 12, 2024
const fs = require('node:fs').promises;
const fileContent = fs.readFile('path_to_file', 'utf-8');
.then
and .catch
:
.then(data => console.log(data))
.catch(error => console.error(error));
node index
async function readFile() {
try {
const data = await fs.readFile('path_to_file', 'utf-8');
console.log(data);
} catch (error) {
console.error(error);
}
}
readFile();