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

248
Views
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 answers
Answer question

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 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!