I'm trying to read JSON from a file using the fs
module, and display that in a div
with id list
in an Electron app. My code in index.js
looks like this:
dialog.showOpenDialog((filenames) => {
if (!filenames) return;
fs.readFile(filenames[0], (err, data) => {
if (err) {
alert('Could not read file.\n\nDetails:\n' + err.message);
return;
}
let json = JSON.parse(data).en;
for (let i = 0; i < json.length; ++i) {
let html = "<div class='entry'><b>";
// Add more to html variable from json data
$('list').html(html);
}
});
});
I get an error saying:
Uncaught Exception:
Error: jQuery requires a window with a document
How do I modify the DOM from the JS, and why do I get this error?