G
G
Galdar Turin2020-01-30 11:31:34
Node.js
Galdar Turin, 2020-01-30 11:31:34

How to return an array from require readline?

Good afternoon everyone, I want to return the temp array from line-by-line reading, what are the ways?

var lineReader = require('readline').createInterface({
                    input: require('fs').createReadStream(tempCatalog+fileDEF)
                });

                lineReader.on('line', function (line) {
                    var list = line.split(';'), operator = list[4].replace(/['"«»]/g, '');

                    if( array.indexOf( operator ) == -1 && temp.indexOf( operator ) == -1 )
                    {
                        temp.push( operator );
                    }

                });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Galdar Turin, 2020-01-30
@Galdar

Thanks to all! I figured it out! It turned out better than I wanted!

async function processLineByLine() {

                var array = await unloadExistOperator(), temp = Array();

                const lineReader = require('readline').createInterface({
                    input: require('fs').createReadStream(tempCatalog+fileDEF)
                });
              
                for await (const line of lineReader) {
                    
                    var list = line.split(';'), operator = list[4].replace(/['"«»]/g, '');

                    if( array.indexOf( operator ) == -1 && temp.indexOf( operator ) == -1 )
                    {
                        temp.push( operator );
                        console.log(list[4])

                    }

                }
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question