title: node js postgres assign value to variable outside scope of then
body: <p>I have to compare few rows derived from potgres with data derived from the dynamo DB. problem is in both cases i have to iterate over data &amp; unless i can assign the value to a variable i will have to query the same data again from either one of two databases. </p>
  
  <pre><code>    function postgressdata(sql){
         return new Promise(function(resolve, reject) {
            client_postgres.query(sql, (err, res) =&gt; {
               resolve(res);
  
             });
         });
      } 
  </code></pre>
  
  <pre><code>let get_creatives =  postgressdata(sql);
  get_creatives.then(function(result) {
    console.log(result); // prints the result
    let new_result = result;
  }
  console.log(new_result) // does not print result
  </code></pre>
  
  <p>How Can I assign the data to a variable here &amp; use it anywhere?
  I am a newbie to NODEJS so pardon me if I am asking silly question.</p>