Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
Assigned global variable does not have global scope

getSecretAsync() is an async method therefore I cannot use await in my config export as it'll be top level. So I created a function to get the secret, however the assigned global variable does not retain its' value, see below.

Could you let me know what I'm doing wrong?

import { newclass } from '../newclass';

var globalVar ="";

const getAsync = async () => {
    const key = await newclass.getSecretAsync("the-secret")
    return key;
  };

  getAsync().then(e=>{
      globalVar = e;
      console.log(globalVar + '****'); // globalVar returns the key 
    });
 
     console.log(globalVar + '**'); // globalVar is empty
 
export const credentials = 
{
    key:globalVar, //globalVar is empty
    region: 'eu', 
    user: 'isi'
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!