Nodejs implements async Synchronize blocking

console.log("a");

(async () => {

    await initDB();

})();


console.log("b");

such as the code above. The order of execution should be
a
b
initDB

the order I expect is

a
initDB
b

because initDB is the connection and initialization of the database, I hope all other operations will be done after this step is completed.

how is it implemented?

Mar.01,2021

drop all the following steps behind await initDB () , otherwise it will be useless for you to use await .

console.log('a');

(async () => {
    await initDB();
    console.log('b');
})();

you can also try

console.log('a');

await (async () => {

    await initDB();

})();

console.log('b');

this should not be necessary to write the latter into the function.

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-1bee6ad-31bee.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-1bee6ad-31bee.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?