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

135
Views
RETURN VALUE FUNCTION ASYNC AWAIT IN RESPONSE EXPRESS

I want to return the value returned by the function getData() I understand that I can't return a promise but how can I return only the data value obtained in the asynchronous function. A response from express

Help please...

const puppeteer = require('puppeteer');

async function getData() {
    req = 'hello';
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://www.abc.com.py/buscar/' + req);
    

    const data = await page.evaluate(() => {
        const $news = document.querySelectorAll('.item-article'); //Corresponde a la clase de Noticias de la pagina
        const dataNews = [];

        ......


            dataNews.push({
                fecha,
                enlace,
                enlace_foto,
                titulo,
                resumen,
            });
        });

        return dataNews;

    })

    return (data);
}

This Response

var express = require('express');
var router = express.Router();
var getData = require('../public/javascripts/script');

//import getData from '../public/javascripts/script';

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});


router.get('/consulta', (req, res) => {
  data = getData.then(val => val);
  res.json(data);
  
})

module.exports = router;

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

0

router.get('/consulta', async (req, res) => {
  data = await getData();
  res.json(data);
})

OR

router.get('/consulta', (req, res) => {
  getData().then(data=>res.json(data));
})
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!