const fs = require('node:fs');
// Blocks execution until the file is fully saved
fs.writeFileSync('greeting.txt', 'Hello, Node.js!\n');
// Blocks execution until the file is fully loaded
const contents = fs.readFileSync('greeting.txt', 'utf8');
console.log(contents); // Hello, Node.js!
// Append a second line without overwriting the first
fs.appendFileSync('greeting.txt', 'Second line added.\n');
console.log(fs.readFileSync('greeting.txt', 'utf8'));