These are chat archives for FMIjs/gitter

2nd
Nov 2015
Aleksander Kostov
@FIZLIN
Nov 02 2015 16:54

var fs = require("fs");

function thingy() {
setTimeout(function () {
fs.writeFile('file1.txt', "Lorem ipsum ", function (err) {
if (err) throw err;

        console.log("It's saved!");
    });
}, 1000);
setTimeout(function () {
    fs.writeFile('file2.txt', "dolar set immet", function (err) {
        if (err) throw err;

        console.log("It's saved!");
    });
}, 1000);
setTimeout(function () {
    var str = "";
    fs.readFile("file1.txt", function (err, data) {
        if (err) throw err;

        str += data;
        fs.readFile("file2.txt", function (err, data) {
            if (err) throw err;

            str += data;            
            fs.writeFile("file3.txt", str, function (err) {
                if (err) throw err;
                console.log("It's saved");
            })
        });
    });
    // Yay! Callback Hell!
}, 1000);

}

thingy();