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

252
Visualizações
Get Response from Express File to Show in Other Javascript File?

So I am trying to add my response.fee value from my express file into another JS file that includes specific functions that update my front end app.

Here is the JS code I am trying to add the express response in. Is this possible?

import response from "express";

window.menuItems = 0;
window.tips = 0;

const tipTotal = document.getElementById("tip");
const orderTotal = document.getElementById("total");

document.addEventListener("click", ({ target }) => {    
  if (target.className === "food" && target.checked) {
    window.menuItems += parseInt(target.value);
  } else {
  return
  }

  tipTotal.textContent = `$${(window.tips / 100).toFixed(2)}`;

  orderTotal.textContent = `$${(
    Number(window.menuItems) +
    Number(window.tips) / 100
  ).toFixed(2)}`;

  console.log(response.fee); //I want to get this value from my express file
});

So I can update the orderTotal code to say this

 orderTotal.textContent = `$${(
        Number(window.menuItems) +
        Number(window.tips) + response.fee / 100
      ).toFixed(2)}`;

Is this something you can do with express? Or it's not possible?

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

0

I'm not so sure whether you're dealing with server-side rendering in your Express application or not but:

  1. Assuming you're not doing SSR: you can make a request to your server (even if it's on the same machine - maybe your laptop or whatever) using fetch (https://developer.mozilla.org/en-US/docs/Web/API/fetch for more details).
  2. However, if you're doing SSR you can start using something like ejs or pug and pass that value stored in response.fee to the res.render function in your Express app (res.render(<FILE_TO_RENDER>, { /* object with values to be passed to the file */ }).
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