0

How can I store results Data into a variable that can I use outside?

My query is like this

let array = [];

const a = 0,
      b = 1;

 if  ( a < b)  {
   const result = await DataClass.findOne({feld:"Word"}).exec();
   array.push(result);
}

// continue ....

console.log(array)

or like this :

let array = [];

const a = 0,
      b = 1;

 if  ( a < b)  {
   await DataClass.findOne({feld:"Word"}).then( result =>{
    array.push(result);
   });
}

// Code continue ....

console.log(array)

How can I store results Data into a variable that can I use outside?

Jaber Alshami
  • 336
  • 3
  • 14
  • 1
    Please see [How do I return the response from an aynchronous call](https://stackoverflow.com/q/14220321/438992), which this duplicates. – Dave Newton Oct 25 '18 at 14:46

1 Answers1

0

Have you tryed environment variables? in .env

ARRAY=''

and in your file

process.env.ARRAY = array
Juan Velasquez
  • 385
  • 4
  • 15