I created sets of async functions in global environment. I want to re-use the async functions across all the modules. When I call the re-use async function in other module, it returned undefined.
Global
module.exports = ((global) => {
return {
async funcA(){
return Promise.resolve();
},
async funcB(){
return Promise.resolve();
}
}
})
Endpoint
module.exports = ((global) => {
return async(req, res, next) => {
var getA = await global.funcA(); // Undefined
};
});
Routes
import global from './global';
console.log(global); // all the scripts
console.log(global.funcA); // Undefined
let endpoint = require('./endpoint')(global);
api.get('/test', endpoint);