title: Javascript insert backslash: __dirname + "index.html"
body: <p>in the question below, someone has given me the following code:</p>
  
  <pre><code>res.end(fs.readFileSync(__dirname + "index.html")); 
  </code></pre>
  
  <p>However this is creating a filename of folderNameindex.html, i.e. there needs to be a backslash before index.html. From googling, the solution should be two x \ within the double quotes, resulting in "\index.html". I've tried this and many other variations, single, double, treble, forward slashes, regex escaping. In every case, my CLI tells me it cannot find file folderNameindex.html.</p>
  
  <p>This is probably simple. Grateful for any help.</p>
  
  <p><a href="https://stackoverflow.com/questions/49750738/can-i-use-node-as-webserver-for-html-app">Can i use node as webserver for html app?</a></p>
  
  <p>EDIT:</p>
  
  <p>My new code:</p>
  
  <pre><code>const http = require('http'),   // to listen to http requests
        path = require('path'),
        fullPath = path.join(__dirname, 'index.html'),
        fs = require('fs');       // to read from the filesystem
  
  const app = http.createServer((req,res) =&gt; {
      // status should be 'ok'
      res.writeHead(200);
  
      // read index.html from the filesystem,
      // and return in the body of the response
  
      res.end(fs.readFileSync(fullPath)); });
  
  app.listen(3000); // listen on 3000
  </code></pre>
  
  <p>I still get the same error - my command line tells me it can't find folderNameindex.html</p>