I have my HTML file, I have my javascript file, I have my .txt files with plain text that I would like to display on my HTML file in the browser.
const fs = require("fs");
let fileUrl = "content";
let files = fs.readdirSync(fileUrl);
function kys(){
let result = "";
for (i in files){
result += fs.readFileSync("content/" + files[i]).toString();
}
return result;
}
This file reads the text file from the "content" folder.
<script src="../scripts/skripti.js"></script>
I've added the javascript file inside my body tag in my HTML file, but I can not for the life of me figure out how to have it display the "result" value that is returned from the function.
Simplest way could be by creating a separate javascript file or adding to that javascript file code that creates a new HTML tag and edits the InnerHTML element, but I get errors that "document" is not defined.
This is probably due to me testing the website through node.js through a VSC extension? I've also tried just opening the HTML file in my browser (Chrome) and no difference.
I've also tried trying to get the function to return the result to a variable, but I run to the error of "document" and "window" not being defined.
Looking through the internet the only solution seems to install npms but I would like to keep this as simple as possible and just latching modules seems like unnecessary bloat.
Creating a script tag and trying to call the function from inside my HTML file doesn't seem to work.
Tl;dr, I have text in file, I want text in web page using javascript, text file is stored locally (on my computer).