Please consider below code. What I want to do is to pick name from names.txt
in createStream
function one by one and from there call FileSear
I manage to resolve the issue by using line-by-line module and now the output is exact as expected. heres the code
var nameToSearch
//Function to retrieve names
var createStream = function (){
var lineNumber=0;
var nameLine = require('line-by-line')
lrName = new nameLine('./names.txt');
//lrName = new nameLine('./names-testFile.txt');
var ended = false;
lrName.on('line', function (lineInNameFile) {
++lineNumber;
nameToSearch=lowercase(lineInNameFile);
FileSearch(nameToSearch);
});
}
var lowercase=function(str){
return String(str).toLowerCase();
}
//Function to search in list file
var FileSearch = function (searchString){
var LineByLineReader = require('line-by-line'),
lr = new LineByLineReader('./list.txt');
//lr = new LineByLineReader('./list-testFile.txt');
var listlineNumber=0
var arr = []
lr.on('line', function (lineInListFile) {
++listlineNumber;
if (lineInListFile===searchString){
arr.push(listlineNumber);
}
});
lr.on('end', function () {
console.log( searchString+ ":" + arr);
});
}
var runSearch = createStream();
exports.createStream = createStream;