I have a specific website where i would like to see how many views a certain page gets, with a text file being edited every time a person clicks on the page. I've tried doing this myself but it did not work out, I am not sure if i have done anything wrong here myself since i am still new to javascript.
var viewC = FileReader.readAsText('./views.txt');
var views = viewC + 1
var viewFile = " " + views +" ";
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
download(viewFile, 'views.txt', 'text/plain');
For a more detailed description of what i would like to happen : "When the user goes to the page, the code will run and add a new value to the text file. The new value is +1 of the old value that is there."
Expected result -
TXT file before
TXT file after a person views it 1
TXT file after the second view 1 2
Or if it is possible to remove the old number and add the new number