title: How to use a basic promise in Node.js when waiting for database
body: <p>I am new to Node.js (usually develop in Java), but I am trying to create a REST service that retrieves data from firebase and then returns it as a JSON object. </p>
  
  <p>I am not familiar with "promises", and after reading up on them, I think I understand the premise, but the implementation had been confusing me. </p>
  
  <p><strong>How can I tell my method to wait for the retrieving of data from my Firebase database?</strong> </p>
  
  <p>Code: </p>
  
  <pre><code>getUsers(): String {
  
      var x;
  
      cooksRef.once('value').then(function(snapshot){
        x = JSON.stringify(snapshot.val())
        console.log("x is: " + x);
      }, function(error){
        console.log("error was: " + error)
      });
  
     console.log("Now x is: " + x);
  
     return x;
    }
  </code></pre>
  
  <p>Currently my code prints out:</p>
  
  <pre><code>Now x is: undefined
  x is: {"R4DA34":{"age":31, "name": "example name"}}
  </code></pre>
  
  <p>I would like for it to wait and execute these statements sequentially, so that I can return the correct data to my controller"</p>
  
  <pre><code>x is: {"R4DA34":{"age":31, "name": "example name"}}
  Now x is: {"R4DA34":{"age":31, "name": "example name"}}
  </code></pre>