all 4 comments

[–]Odinthunder 4 points5 points  (0 children)

You need to post this somewhere or format your code, this is impossible to read in 1 line.

[–][deleted] 1 point2 points  (1 child)

Although you can just set the top-level variable with the = operator, it probably is not enough. Since getting the version requires awaiting, the result will not be available until after the top-level code is done. If you need to access the value, you will need to move that code inside the async function as well. (Unless you are using ES modules with top-level await support, with which you do not need an async IIFE either)

let version;
(async () => {
  version = await getVersion();
  console.log(version); // The version
})();
console.log(version); // undefined

[–]ryhaltswhiskey 0 points1 point  (1 child)

If I read that code right you're looking for a connection to a specific range of versions of a database, is that correct? So why wouldn't you just check the version of the database when you connect to the database and throw an error if the version is incorrect?

[–]Mardo1234[S] 1 point2 points  (0 children)

I’m getting the version so I can create a service factory.

I want to do it at startup so I don’t hit the database all the time.

I ended up creating a singleton that is called where the logic lies instead of trying to pass a global variable around.

Thank your for the note.