Nodejs crawler loops to get data

wants to implement the function of port scanning, such as 192.168.1.666 - 192.168.1.666

uses nodejs + express + cheerio

personal idea: circular port, use superagent to grab the port of ip between 80-10000, if the port does not exist, then jump out of this loop, then execute next time, declare data variable, if there is content in the port and grab website title, push to data ,
finally when executing to the maximum interface, res.send (data)

problem encountered: keep going in circles, turning the loop down is the same, I don"t know what the problem is, whether it needs to be asynchronous or there is something wrong with the code?

Code:

const express = require("express");
var cheerio = require("cheerio");
const superagent = require("superagent");
const app = express();

/ / crawl address

var url = "http://47.74.xxx.xxx";
var maxport = 8085;
var data = [];
for(let port = 8082; port < maxport ; portPP){
    app.get("/", function (req, res, next) {
    superagent.get( url + ":" + port )
        .end(function (err, sres) {
            if (err) {
                return next(err);
            }
            const $ = cheerio.load(sres.text);
            let items = $("title").text();
            data.push(items)
            
            if(port >= maxport){
                res.send(data);
            }
            
    
        })
    });
}

app.listen(3000, function () {
    console.log("app is listening at port 3000");
});

it is better to provide the code


const EventProxy = require('eventproxy');
const ep = new EventProxy();
let maxPort = 10000;
let portList = [];
let data = [];
const url = xxx.xxx.xxx.xx;
for(let port = 8082; port < maxPort; port PP) {
    portList.push(port);
}

portList.forEach((port) => {
    superagent.get( url + ':' + port )
    .end(function (err, sres) {
        if (err) {
            return ;
        }
        ep.emit('port', sres); //
    });
    
})

ep.after('port', maxPort - port, function(ports) {
    data = ports.map((item) => {
        const $ = cheerio.load(item.text);
        let title = $('title').text();
        return title;
    });
    console.log(data);
})

app.get('/', function(req,res, next) {
    res.send(...)
});

your problem boils down to how to handle asynchronously in nodejs and for loops

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea1819-1b62.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea1819-1b62.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?