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

186
Views
fetch devuelve constantemente Promise {<pending>}

Decidí crear un servicio especial, también conocido como clase ES6, con las funciones necesarias para obtener datos de la API y luego, en index.js, pude crear una instancia de la clase y trabajar con ella. Desafortunadamente, cuando lo pruebo, siempre regresa.

Promesa {<pendiente>}

y la verdad no se que hacer

nytService.js:

 export default class NYTService { urlBase = "https://api.nytimes.com/svc/topstories/v2/"; category = "world"; apikey = *my api key* ; async getNews(category = this.category) { let url = `${this.urlBase}${category}.json?api-key=${this.apikey}`; let res = await fetch(url) let data = await res.json(); return data; } }

índice.js:

 import NYTService from "../services/nytService.js"; let nytService = new NYTService(); async function getNewsFinally() { let res = await nytService.getNews(); return res; } console.log(getNewsFinally());

Intenté diferentes cosas con la función getNewsFinally, hice varias cadenas .then, nada ayudó

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

0

A ver si esto te dice por qué:

 async getNews(category = this.category) { let url = `${this.urlBase}${category}.json?api-key=${this.apikey}`; try { let res = await fetch(url) if (!res.ok) { return res.statusText; } return await res.json(); } catch(err) { console.error(err); throw new Error(err); } }
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!