New to node/express. I am using it as a sort of "middle-man" API from which I make API calls to my node app which makes API calls to Discord's API. I have some data that I get once Discord's API is "ready", and I need that data in subsequent API calls.How can I pass this data to my module.exports?Example:Set guild data in index.js when Discord API is "ready" and guild data is returned from APIPass guild data to other routes' module.export (these will be called from actions on a website)index.jslet guild = null; require("./route1")(app, guild); // obviously doesn't work as guild is null still client.once("ready", () => { guild = setGuildById(guildId); }); route1.js// guild is always null here because it doesn't wait for it to be set module.exports = (app, guild) => { app.post("/url1/", (req, res) => { ... }) }
Submitted June 04, 2020 at 12:05PM by springloading
No comments:
Post a Comment