JAVASCRIPT FILE
const path = require('path');
const http = require('http');
const fs = require('fs');
const dir = '../frontend/';
const server = http.createServer((request, respond) => {
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) => {
if (error) throw error;
files.forEach((file) => {
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');
HTML File
<div class="container"></div>
Whenever I'm trying to execute above code it gives me an error like this
document.querySelector('.container').innerHTML = file;
^
ReferenceError: document is not defined
at D:\Framework Final\backend\server.js:26:19
at Array.forEach (<anonymous>)
at D:\Framework Final\backend\server.js:23:13
at FSReqCallback.oncomplete (fs.js:171:23)
Can anyone tell me how can I achieve the same without getting an error.