I want to break the loop if condition response.body.includes("Your file is ready") is true.
When I run my code, I get my source in subContent, but the loop doesn't stop. I'm sending server the request to allows 20 requests in 24 hours so I need to break the loop.
const arrow = async (proxy) => {
return new Promise(function(resolve, reject) {
var agent = new HttpsProxyAgent('http://'+proxy)
var proxyRequest = request.defaults({
agent: agent,
timeout: 5000,
headers: {
'user-agent': 'xxx'
}
})
proxyRequest.get("xxx", async function (error, response, body) {
if(!error) {
if(response.body.includes("Your file is ready")) {
resolve(body)
}
}
})
})
}
function getData(data) {
return new Promise( async function(resolve, reject) {
data.forEach(async (proxy) => {
let content = await arrow(proxy)
if(content.includes("Your file is ready")) {
return resolve(content)
}
})
})
}
(async () => {
let proxies = fs.readFileSync("proxies.txt", {encoding:'utf8', flag:'r'}).split(/\r?\n/)
const subContent = await getData(proxies)
console.log(subContent)
})()