Node.Js Document Is Not Defined

Node.js document is not defined

document relates to the DOM (Document Object Model) in a web browser.

Node.js, however, is not a browser environment. It is a server environment, much like PHP or Perl, and as such, you can’t access the browser’s DOM or do anything specific to browser-hosted JavaScript.

The closest you could get is using something like browserify to include Node.js modules in your client-side code.

ReferenceError: document is not defined (JavaScript in VS Code)

In your screenshot, you're attempting to run the script using Node.js (the server-side JavaScript executable).

Since you say you're running live-server, you should be looking at your browser instead, not trying to run your code via Node.



Related Topics



Leave a reply



Submit