title: Promise isn't resolving on node.js
body: <p>I'm having a lot of problems with node.js/Promises at the moment. Currently I'm doing something simple as this:</p>
  
  <p><strong>module.js</strong></p>
  
  <pre><code>var fs = require('fs');
  
  function myFunction() {
      var files = []; 
      for (var i = 0; i &lt; 100; ++i) {
          files.push(fs.writeFile("file-" + i + ".txt", "file" + i, "utf-8", function(err) {
              if (err)
                  throw err;
          }));
      }
      Promise.all(files).then(function() {
          return new Promise(function(resolve, reject) {
              resolve('ok');
          })
      });
  }
  exports.myFunction = myFunction;
  </code></pre>
  
  <p><strong>main.js</strong></p>
  
  <pre><code>var test = require('./module.js');
  
  test.myFunction().then(function(result) {
      console.log(result);
  })
  </code></pre>
  
  <p>Yet, my output if I run my main.js is:</p>
  
  <pre><code>module.myFunction().then(function(result) {
                     ^
  
  TypeError: Cannot read property 'then' of undefined
  </code></pre>
  
  <p>I don't know why my module is returning a Promise as undefined. Can anybody help me out here? I just can't wrap my head around this. Thank you very much!</p>
  
  <p>And, while <code>writeFile()</code> writes the files as file-0.txt and so on, the files have no content at all.</p>