title: Node.js writeFile [Uncaught TypeError: Cannot read property 'writeFile' of undefined]
body: <p>I can't get writeFile to write file. It works find if it's not in a function so it's not the module but when the function is called, it results in an error.</p>
  
  <blockquote>
    <p>[Uncaught TypeError: Cannot read property 'writeFile' of undefined]</p>
  </blockquote>
  
  <p>JS Code:</p>
  
  <pre><code>var fs = require('fs');
  var input = document.getElementById('filename');
  var fileName = input.value;
  
  function recordToFilename() {
  var input = document.getElementById('filename');
  var fileName = input.value;
  var qw = fileName;
  
  if (qw) {
      alert('value of: ' + qw);
      console.log(qw);
      // demo output
      var myObject = {
          qw: qw,
          fullN: function() {
              return this.qw;
          }
      };
  
      document.getElementById("demo").innerHTML = myObject.fullN();
      var path = "danny.txt";
      var data1 = "jdsfhadj"
      fs.writeFile(path,data1)
      //end demo output code
      } else {
          alert('Please enter a filename!');
          input.focus();
      }
  };
  </code></pre>
  
  <p>HTML Code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;writeFile&lt;/title&gt;
      &lt;script src="jquery.js"&gt;&lt;/script&gt;
      &lt;script src="bonescript.js"&gt;&lt;/script&gt;
      &lt;script src="test_3.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;label for="filename"&gt;Filename&lt;/label&gt;
      &lt;input name="filename" id="filename" type="text"&gt;
  
      &lt;a id="enter_button" onclick="recordToFilename();"    href="javascript:void(0);" title="enter"&gt;enter name&lt;/a&gt;
      &lt;br&gt;
      &lt;p id="demo"&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>