title: How can I access DOM Elements using Node JS?
body: <p><strong>JAVASCRIPT FILE</strong></p>
  <pre class="lang-js prettyprint-override"><code>const path = require('path');
  const http = require('http');
  const fs = require('fs');
  
  const dir = '../frontend/';
  
  const server = http.createServer((request, respond) =&gt; {
        console.log(request.url);
  
        respond.writeHead(200, {
              'Content-Type': 'text/html',
        });
  
        const readStream = fs.createReadStream(dir + 'index.html', 'utf-8');
        readStream.pipe(respond);
  });
  
  const icons = 'icons/';
  
  fs.readdir(icons, (error, files) =&gt; {
        if (error) throw error;
  
        files.forEach((file) =&gt; {
              if (path.extname(file) == '.svg') {
                    // I want to append this filename in the DOM Element.
                    document.querySelector('.container').innerHTML = file; // Like This
                    // console.log(file); 
              }
        });
  });
  
  server.listen(3000, 'localhost');
  </code></pre>
  <p><strong>HTML File</strong></p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;container&quot;&gt;&lt;/div&gt;
  </code></pre>
  <p>Whenever I'm trying to execute above code it gives me an error like this</p>
  <pre><code>                  document.querySelector('.container').innerHTML = file;
                    ^
  
  ReferenceError: document is not defined
      at D:\Framework Final\backend\server.js:26:19
      at Array.forEach (&lt;anonymous&gt;)
      at D:\Framework Final\backend\server.js:23:13
      at FSReqCallback.oncomplete (fs.js:171:23)
  </code></pre>
  <p>Can anyone tell me how can I achieve the same without getting an error.</p>