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

541
Views
ReferenceError: document is not defined in Visual Studio Code

Why wouldn't node.js recognize my index.html reference in the script.js file?

Pardon me for the dumb question but I couldn't find any fix and I've done copied perfectly a script from a YouTube tutorial and they seem to have no problem (neither do others, same method) but when I get to run node script.js in the terminal (or refreshing the html page in browser) nothing seems to work as it should and the html page remains static. I tried browsify and jsdom and what other suggested before in here but I wasted the same time with those too.

So here it is, even put it twice, once above </body> and once above </head>:

<script scr="script.js"defer></script>
...
    <div class="countdown-days-c">
        <p class="big-text"id="days">0</p>
        <span>days</span>
    </div>

And in the JS file like:

const daysElement = document.getElementById("days");

followed by this error

ReferenceError: document is not defined
    at Object.<anonymous> (C:\Users\......\script.js:6:16)
    at Module._compile...

and so on. Maybe I just missed something but I did exactly as shown and I've been struggling with this for some time now. I don't have any problem with the CSS file and the JS file can run perfectly standalone, but can't seem to work with the HTML.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't run the app in node because the global objects are different. What you should do is open the HTML file in the browser instead. That should solve all your problems.

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!