Answer the question
In order to leave comments, you need to log in
How to return the result of an async function from require?
I need to get the result, an object with keys, which I initialize once. How can I get the result and not the callback function?
const channels = require('../boot/channels')
module.exports = () => {
console.log(channels)
}
const Mongoose = require('mongoose');
const Location = require('../models/location');
module.exports = async () =>{
try {
let locs = await Location.find({});
let channels = {
}
for (loc of locs) {
channels[loc.id] = 0;
}
return channels
} catch (err) {
console.error(err);
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question