title: Create Directory When Writing To File In Node.js
body: <p>I've been tinkering with Node.js and found a little problem.  I've got a script which resides in a directory called <code>data</code>.  I want the script to write some data to a file in a subdirectory within the <code>data</code> subdirectory.  However I am getting the following error:</p>
  
  <pre><code>{ [Error: ENOENT, open 'D:\data\tmp\test.txt'] errno: 34, code: 'ENOENT', path: 'D:\\data\\tmp\\test.txt' }
  </code></pre>
  
  <p>The code is as follows:</p>
  
  <pre><code>var fs = require('fs');
  fs.writeFile("tmp/test.txt", "Hey there!", function(err) {
      if(err) {
          console.log(err);
      } else {
          console.log("The file was saved!");
      }
  }); 
  </code></pre>
  
  <p>Can anybody help me in finding out how to make Node.js create the directory structure if it does not exits for writing to a file?</p>