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

322
Views
How to pass data from NodeJS API as a variable to a static JS file?

I have made a NodeJS REST API, which returns JSON data of questions I have a static JS file which does DOM manipulations on client side to show different questions in an order, it takes questions from the questions array.

I am able to get data from the API on the pug render engine and to pass it on the main page, but unable to find a way to pass that data as a variable to the JS file which does DOM manipulation on the page.

I have thought of an approach to fetch data from API in the static js file itself but it doesn't seem to be an effective approach because request to API is done in the render engine itself.

My viewsConroller:

viewController

My pug template is able to access the questions:

pug template and rendered page

but I can't find a way to send questions array as a variable to the static JS file which does the DOM manipulation.

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

0

I think fetching the json data in your static js file would be the best thing. Other than that you could do this:

let questions = document.querySelectorAll('.overview-box__text').map((el) => JSON.parse(el.innerText));
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!