Skip to content
Advertisement

How to pass array inputs as parameter to async function?

I got set of urls from txt file [which I am having in my local] which I got as array inputs with below code

JavaScript

Sample output when I do console.log(testurls) [ ‘https://sample1.com’ ‘https://sample2.com’ ]

How to pass the values to below function as parameter/argument to run scan on each url one after other as I am trying to some performance test using light house?

JavaScript

Advertisement

Answer

Easy way? Use fs.readFileSync() to load that text file.

Harder way, but better if the file is large? Promisify the reading of the file so you can call it with await. Then use a loop to do your puppeteer thing.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement