Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

329
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda