title: Node.JS - Promises do not wait to resolve
body: <p>I am using the <a href="https://github.com/apocas/dockerode" rel="nofollow noreferrer">dockerode</a> for manipulate docker from node.js. The library it self is not the problem but i am have issues with PROMISE. It seems the promise do not wait to resolve. </p>
  
  <p>The code below I expected the output will be:</p>
  
  <pre><code>Start
  Middle // (or Err if docker does not running)
  End
  </code></pre>
  
  <p>But I am receiving: </p>
  
  <pre><code>Start
  End
  Middle
  </code></pre>
  
  <p>It seems the promise is not waiting to continue the javascript running flow. What I am doing wrong?</p>
  
  <pre><code>const Docker = require('dockerode')
  let docker = new Docker();
  
  console.log('Start');
  let promise = new Promise(function (resolve, reject) {
      docker.listContainers({all: true}, function (err, data) {
          if (err) {
              reject(err)
          } else {
              resolve(data);
          }
      });
  });
  
  promise.then(function (data) {
      console.log('Middle');
  }, function (err) {
      console.log('Err');
  });
  
  console.log('End');
  </code></pre>
  
  <p>Copy and paste this code on <a href="https://npm.runkit.com/dockerode" rel="nofollow noreferrer">https://npm.runkit.com/dockerode</a> or see the result here: <a href="https://runkit.com/embed/y3wvg6ktecb9" rel="nofollow noreferrer">https://runkit.com/embed/y3wvg6ktecb9</a></p>