Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Getting "document is not defined" in JS

I'm trying to build a simple Blackjack game, and everything was going well, until I started getting the error "document is not defined"... I'm using VS Code with Node, so I just write in the terminal "node index.js" and it always works, however for some reason it's not working now.

Here's the error:

let messageEl = document.getElementById("message-el");
                ^

ReferenceError: document is not defined
    at Object.<anonymous> (C:\Users\draven\Desktop\JAVASCRIPT\Blackjack\index.js:9:17)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

node runs in a server environment, which doesn't have any document or window because it is not a browser environment.

about 4 years ago · Juan Pablo Isaza Report

0

document is a web browser concept, it doesn't exist in the node runtime.

Check out this answer for the a great explination: Document in node

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!