I am following a youtube tutorial the guy in the tutorial is able to execute the code in the browser but i am unable to do the same. The following is the error that pops up in the terminal.
C:\vs projects\booklistapp\bookapp.js:47
document.addEventListener('DOMContentLoaded
', UI.displayBooks);
^
ReferenceError: document is not defined
at Object.<anonymous> (C:\vs projects\b
ooklistapp\bookapp.js:47:1)
at Module._compile (internal/modules/cj
s/loader.js:778:30)
at Object.Module._extensions..js (inter
nal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/lo
ader.js:653:32)
at tryModuleLoad (internal/modules/cjs/
loader.js:593:12)
at Function.Module._load (internal/modu
les/cjs/loader.js:585:3)
at Function.Module.runMain (internal/mo
dules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:
283:19)
at bootstrapNodeJSCore (internal/bootst
rap/node.js:622:3)```
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3indicates that you try to run the script using nodejs. And the stack trace doe snot indicated that you use any module that tries to emulate a browser environment that would providedocument. Anddocument.addEventListener('DOMContentLoaded', UI.displayBooks);is clearly a code that belongs in a browser environment (or in the ui part of e.g. electron - which is actually a browser).