How does Node.JS get the result of asynchronous processing and return to the outermost layer?

for example,
I want to read a json file, convert the content to string, and then use JSON.paras to convert it into a JSON object.
I"m confused right now. Please give me some guidance.

//
let result = require("./func").read2JSON("db/list.json");
console.log(result);
The

result shows undefined.
, so how exactly do you return the result to the outermost layer? What exactly is this principle?

Mar.20,2021

use async/await, to finish asynchronous execution and then return


gives you several ways to write:

callback form:

require('./func').read2JSON('db/list.json').then(result => {
    console.log(result);
});
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-1b2c201-2bae3.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-1b2c201-2bae3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?