Работа с файлами / Текстовые файлы

//using Node.js
//npm i @types/node
const fs = require("fs");

let filePath = "file.txt";

//Asynchronously:
fs.writeFile(filePath, 
    "Line 1\nLine 2", (err) => {
    if (err) 
        console.log("Error:", err);
    else
        console.log('Text written to file!');
});

//Synchronously:
try { 
    fs.writeFileSync(filePath, "Line 1\nLine 2");
    console.log("Successfully written!");  
catch(e) {
    console.log('Error:', e.stack);
}