title: NODEjs - write data from mysql to file
body: <p>i am currently trying to use node and so far it is good,
  but my problem is I query the database and i get the result back.
  but when i try to write file i get errors, </p>
  
  <p>I have tried this way</p>
  
  <pre><code>fs.writeFile('table.txt', rows, 
                function (err) {
                     if (err) throw err;
                     console.log('Saved!');
  }); 
  </code></pre>
  
  <p>and another way </p>
  
  <pre><code>var stream = fs.createWriteStream("my_file.txt");
   stream.once('open', function(fd) {
       for (var i = 0;i &lt; rows.length; i++) {
             stream.write('test: ', rows[i].i);
        }
  
        stream.write("My first row\n");
        stream.write("My second row\n");
        stream.end();
    });
  </code></pre>
  
  <p>I don't know what i am doing wrong, i have spend a few hours now looking 
  any suggestions or Idea's</p>
  
  <p>thanks in advance </p>