Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
Node js error: document is not defined at Object.<anonymous>

After running this simple commands in vscode:

let pageBanner = document.getElementById('page-banner');
console.log(pageBanner);

code runner plugin is installed but WHY output in terminal is this:

PS D:\VSprojs\vs-advanced-one> node "d:\VSprojs\vs-advanced-one\two\script.js"
d:\VSprojs\vs-advanced-one\two\script.js:3
let pageBanner = document.getElementById('page-banner');
                 ^

ReferenceError: document is not defined        
    at Object.<anonymous> (d:\VSprojs\vs-advanced-one\two\script.js:3:18)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)     
    at node:internal/main/run_main_module:17:47

in html file there is this:

<body>
    <div id="container">
        <header>
            <div id="page-banner">
                <h1 class="title">OpenBook</h1>
          <form id="search-books">
            <input type="text" placeholder="Search books..." />
          </form>
            </div>
        </header>

in its css file :

#page-banner{
    background: #eee ;
    padding: 10px 0;

}

#page-banner h1, #page-banner p{
    width: 100%;
    text-align: center;
    margin: 10px 0;
}

#page-banner input{
    width: 90%;
    max-width: 300px;
    margin: 20px auto;
    display: block;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
    color: #444;
}

I'm a beginner programmer but I know that the document object stores elements of an HTML document such as html, head, body and other HTML tags as objects, my main question is that the output of this problem in vscode is clear and sufficient For a novice programmer?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The document object is a browser API (https://developer.mozilla.org/en-US/docs/Web/API/Document), so if you run your code in node, in there it does not exist. You have to run the code in the browser to be able to use the document object.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda