title: recursively watch a directory with node.js api
body: <p>I'm trying to recursively watch a directory and I'm stumbling upon a namespace issue.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>for (i in files) {
      var file = path.join(process.cwd(), files[i]);
      fs.lstat(file, function(err, stats) {
          if (err) {
              throw err;
          } else {
              if (stats.isDirectory()) {
                  // Watch the directory and traverse the child file.
                  fs.watch(file);
                  recursiveWatch(file);
              }   
          }   
      }); 
  }
  </code></pre>
  
  <p>It appears that I'm only watching the last directory stat'd. I believe the problem is that the loop finishes before the lstat callback is finished. So every time the lstat callback's are called, file = . How do I address this? Thank you!</p>