1

I got an error for const weatherForm = document.querySelector('form') ^

ReferenceError: document is not defined at Object. (/Users/sheebadola/development/quadacademy/work/task-6/Webserver/src/app.js:98:21) at Module._compile (node:internal/modules/cjs/loader:1226:14) at Module._extensions..js (node:internal/modules/cjs/loader:1280:10) at Module.load (node:internal/modules/cjs/loader:1089:32) at Module._load (node:internal/modules/cjs/loader:930:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47

Node.js v18.14.0

I tried to move the to the bottom of the in HTML and still there's no fix. What can I use instead of document, how do i manipulate DOM ?

3
  • 2
    because there isn't any HTML in node.js? Commented Mar 7, 2023 at 17:46
  • Does this answer your question? Is it possible to manipulate DOM in node js? Commented Mar 7, 2023 at 17:48
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 7, 2023 at 17:54

1 Answer 1

1

When you have a <script> element in an HTML document (and open it in a browser) the entire JavaScript environment is centred about that document.

It goes browserdocumentscript

The browser provides a bunch of APIs including the document.


When you run a JS program with Node JS, there is no HTML document.

It goes Node.jsscript

It isn't centred around an HTML document, so no document object is provided for you.

Node.js provides a different collection of APIs (mostly listed in the table of contents for its documentation), mostly through its built-in modules.


In Node.js, you could create a document object using a DOM library, but you are not running your script inside a document.

You've tagged this . When using Express it is typical to generate HTML using a template engine and not with DOM manipulation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.