How node.js implement async-callback with single process

I don't know how node implement its amazing idea. And i have a question when use it.
I have to read four files file1.js file2.js file3.js file4.js and concat them into one big javascript file result.js. It's important to keep their order.

So it's normal for me to use readFileSync instead of readFile.
I know it's a bad solution. Anyone has a good idea to do that?

Q: Is it possible for node.js to read four files at the same time?

Hope someone can explain the principle of node.js and when process.nextTick will be fired.

A: yes it is possible for node to read 4 files at the same time.

My answer would be, it depends on your situation, for reading the files synchronously or asynchronously. If it's configuration data, or the files can be cached, I would suggest just doing it synchronously, it's easy, and it's only done once. So you won't be waiting around very much. Long operations on initialization are typical, and can make things in the long run more efficient. That being said, reading four files in order, asynchronously, so that your program can do other things in the background isn't that hard. I will work on sync and async examples of each and add an edit.

/* jshint node:true*/

var fs = require('fs');

function readFilesSync(fileNames) {
    'use strict';
    var results = '';

    for (var i = 0; i < fileNames.length; i++) {
        results += fs.readFileSync(fileNames[i]);
    }

    return results;
}

function readFiles(fileNames, callback) {
    'use strict';
    var results = '';

    function readFile(index) {
        if (index < fileNames.length) {
            fs.readFile(fileNames[index], function (err, data) {
                results += data;
                readFile(index + 1);
            });
        } else {
            callback(results);
        }
    }

    readFile(0);
}

function readAllFilesAtOnce(fileNames, callback) {
    'use strict';
    var results = {};
    var numFiles = fileNames.length;

    function callBackWrapper() {
        var resultsOrdered = '';

        for (var i = 0; i < fileNames.length; i++) {
            resultsOrdered += results[fileNames[i]];
        }
        callback(resultsOrdered);
    }

    function readFileAsync(fileName) {
        fs.readFile(fileName, function (err, data) {
            results[fileName] = data;
            numFiles--;

            if (numFiles === 0) {
                callBackWrapper();
            }
        });
    }

    for (var i = 0; i < fileNames.length; i++) {
        readFileAsync(fileNames[i]);
    }

}

function doSomethingWithTheData(data) {
    'use strict';
    console.log('Results async: ' + data);
}

function doSomethingWithTheData2(data) {
    'use strict';
    console.log('Results async all at once: ' + data);
}

var fileNamesArray = ['blah.js', 'file.js', 'hello.txt'];

console.log('The results sync: ' + readFilesSync(fileNamesArray));

readFiles(fileNamesArray, doSomethingWithTheData);

readAllFilesAtOnce(fileNamesArray, doSomethingWithTheData2);

EDIT: There I added a method to read all of the files at once.

Process.nextTick does no more than process this function on the next time around the event loop. EX:

process.nextTick(function() {
    console.log('never printed out');
});

while(true);

ex 2:

process.nextTick(function() {
        console.log('printed last');
});

console.log('printed first');