How does Promise + exports output values directly instead of promise objects?

a.js

// a.js
module.exports = {
    list: async () => {
        return await axios.get(getIntelligentPlatform)
    },
}

b.js

// b.js
const { list } = require("../models/meibrain")
// 
list().then(res => {
    console.log(res.data.obj)
})

I hope list in b.js file require is the requested data

Mar.03,2021

Let me tell you the conclusion directly. there is no way .

the direct output value you are talking about, in essence, only the Synchronize operation can directly output the value.

for asynchronous operations, either callback or Promise is used. Both of these values cannot be output directly.

and the only one similar to the direct output value is async .

const { list } = require('../models/meibrain')
(async()=>{
    let res = await list();
})()

async/await allows you to write asynchronously just like writing Synchronize, but it is essentially a syntax candy for Promise .

Menu