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

295
Visualizações
How can I import a const from a vanilla Js file that has DOM elements to my express server?

I'm using Firebase to add auth to my site, and I want to export the user const into the express so I can pass it to a route. This is the function to create the user.

const signupForm = document.getElementById('signup');
if (signupForm) {
    signupForm.addEventListener('submit', (e)=>{
        e.preventDefault();
        const email = signupForm.email.value;
        const password = signupForm.password.value;
        createUserWithEmailAndPassword(auth, email, password)
        .then((cred)=>{
            return cred.user;
        })
        
        signupForm.reset();
    })
}

But when I require anything from the firebase file into express I keep getting this error

 const signupForm = document.getElementById('signup');
                    ^
 ReferenceError: document is not defined

I understand that the error is because document is DOM related and can't be run in express, but is there a way for me to export only the user const into express? any help is appreciated and thank you.

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

0

What you need to do is to send a POST request to the route, because the express server and the web page you load are completely separeted.

Add a fetch request like this:

            fetch('/api/users', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(cred.user)
            }

And the you handle the data in express.

over 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
Assistente virtual