title: Create a file in public folder of an Express.js App
body: <p>I have been trying to create a simple html file in the public folder of my Express.js app, but can't get the path right. Can anybody help me out?</p>
  
  <p>Here is the part of my app.js where I configure my static folder:</p>
  
  <pre><code>app.use(express.static(path.join(__dirname, 'public')));
  </code></pre>
  
  <p>and here's the code I'm using to try to create the index.html file in the public folder:</p>
  
  <pre><code>exports.index = function(req, res){
      var fs = require('fs');
      fs.openSync(__dirname + "/public/static_html/index.html", 'w')
  };
  </code></pre>
  
  <p>However, node.js throw an error:</p>
  
  <blockquote>
    <p>500 Error: ENOENT, no such file or directory 
    'C:\nodejs\node_modules.bin\myapp\routes\public\static_html\index.html'</p>
  </blockquote>
  
  <p>Why is it pointing to the to the public folder inside <strong>"routes"</strong>?</p>
  
  <p>I would like the path to be:</p>
  
  <blockquote>
    <p>'C:\nodejs\node_modules.bin\myapp\public\static_html\index.html'</p>
  </blockquote>
  
  <p>Can anybody help please?</p>