0

In this function a json file will be read and processed by nodes filesystem and the data object will be pushed into an array. I do this twice after another. My problem is, that my initialized array 'fileArray' doens't contain any data, it stays empty. I just can't figure out what the problem might be in here.

var fileArray = [];

(function  () {

    fs.readFile('artists.json', {encoding: 'utf-8'}, function (err, data) {
        if (err)throw err;
        fileArray.push({
            index: {
                _index: 'data',
                _type: 'gallery',
                artists: data
            }
        })
    });

    fs.readFile('works.json', {encoding: 'utf-8'}, function (err, data) {
        if (err)throw err;
        fileArray.push({
            index: {
                _index: 'data',
                _type: 'gallery',
                works: data
            }
        })
    });

})();

console.log(fileArray);
adeneo
  • 312,895
  • 29
  • 395
  • 388
d3x
  • 655
  • 1
  • 5
  • 11

0 Answers0