I am studying callbacks, and for some reason I can't get it right... I want to read a file, and save it's data to a global variable to play with later.
Here is what I have so far:
var fs = require("fs");
var readline = require("readline");
var i = 0;
var total = 66; //put the total foldernames or total images (same number)
var folder_names = [];
var data = [];
lineReader = readline.createInterface({
input: fs.createReadStream("folder-names and data.txt")
});
lineReader.on('line', function(line, dataCollector) {
if(i<66)
folder_names.push(line);
else
data.push(line);
dataCollector(folder_names, data);
i++;
});
var dataCollector = function(folder_names, data) {
//console.log(folder_names);
}
console.log(folder_names[0]); //should have a value now.
What is wrong? I get: dataCollector is not a function