How does nodejs return data asynchronously?

The row of

asterisks will print out that the data that should be return in the undefined,
search function has the data I need, and there is no data on the
page. Where is the problem?

the data format of the page request is

async function search(searchtext) {
    var resdata = {};
    // 
    if (safetytest(searchtext)) {
        pool.getConnection(function (err, connection) {
            if (err) throw err;
            connection.query(
                "SELECT * FROM `***` where ***=?",
                searchtext,
                function (err, result) {
                    if (err) throw err;
                    resdata = {
                        uid: result[0].uid,
                        aname: result[0].aname,
                        lng: result[0].lng,
                        lat: result[0].lat,
                        address: result[0].address,
                        telephone: result[0].telephone
                    };
                    return resdata;
                }
            );
        });
    }
}
Mar.04,2021

pool.getConnection and connection.query if there is no promise/async, you can implement each promise manually.

function search(searchtext) {
    return new Promise((resolve, reject) => {
        var resdata = {};
        if (safetytest(searchtext)) {
            pool.getConnection(function (err, connection) {
                if (err) reject(err); // reject
                connection.query(
                    function (err, result) {
                        if (err) reject(err); // reject
                        resdata = {
                        };
                        resolve(resdata); // resolve
                    }
                );
            });
        }
    })
}

if there is, this may be the case.

async function search(searchtext) {
    var resdata = {};
    // 
    if (safetytest(searchtext)) {
        try {
            const connection = await pool.getConnection()
            const resdata = await connection.query()
            return resdata
        } catch (err) {
            throw err
        }
    }
}
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-1b323f8-e34a.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-1b323f8-e34a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?