Lmao 123
Lmao 123

Reputation: 131

Add 2 Line-By-Line text readers in one function

I want to read 2 different text files, the keys.txt file and the proxies.txt file. When reading keys.txt start a function and read proxies.txt to add something in that function.

var LineByLineReader = require('line-by-line'),
    lr = new LineByLineReader('keys.txt');
    ls = new LineByLineReader('proxies.txt')


lr.on('line', function (line) {
    console.log(chalk.blueBright("Going next to: " + line))
    lr.pause();
     x = x+1  //ignore this, it is my max readers per second
    if(x<=10){ 
        try {
    (async () => {
       ls.on('line', proxy) .then(proxy => { 
        const browser = await puppeteer.launch({headless: true, devtools: false,
            args: [`--proxy-server=http://${proxy}`]
        })
        const page = await browser.newPage()

       })})} catch(err) {throw(err)}}})

I need to use the lines from proxies.txt into my code, however I can't do it because it starts 2 separate functions. (if I use ls.on('line', function proxy { CODE })). The line ls.on('line', proxy) .then(proxy => { doesn't seem like working for some reason.

Upvotes: 0

Views: 68

Answers (1)

Lmao 123
Lmao 123

Reputation: 131

I did it. I used

ls.on('line', (proxy) => {
    ls.pause();

Before the code. Now for each line it reads both text files line by line, and executes the function I need.

Upvotes: 0

Related Questions