-2
module.exports = app => {
  app.on(['pull_request.opened'],async context => {
    let id = 'some string'
    exports.id = id
  })
}

I am new to javascript. I want to export the 'id' variable to other module, but i am not able to read it in the other module. Is there any way to do it?

  • 1
    Possible duplicate of [How to export a variable that takes its value from an async function](https://stackoverflow.com/questions/49798540/how-to-export-a-variable-that-takes-its-value-from-an-async-function) – Ben Fortune Mar 05 '20 at 13:16
  • You will be able to access it, the problem is that you won't be able to *wait* until you would be able to use it. – Bergi Mar 05 '20 at 13:17

1 Answers1

-1

try this; it may work:


module.exports = app => {
  app.on(["pull_request.opened"], async context => {
    let id = "some string";
    //Just return the id, if you want to export more than one thing(id), you can use an object.
    return id;
  });
};

//Usage
//Where_i_use_it.js
const MyApp = require("./path/to/MyApp");

console.log(MyApp()); // ==> "some string" ```
Dahkenangnon
  • 66
  • 1
  • 9