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

143
Views
establecer un intervalo para actualizar una API después de x tiempo

Tengo un servidor de nodos que obtiene la api de la NASA apoc api. Quiero que el servidor de nodos realice una solicitud cada 24 horas y obtenga el último JSON. Intenté establecer un intervalo a través de la función y no funcionó.

 import http from 'http'; import fetch from 'node-fetch'; import "./schema.mjs" import { lastSol } from './schema.mjs'; const hostname = 'localhost'; const port = 3001; const server = http.createServer(async (req, res) => { res.statusCode = 200; res.setHeader('Access-Control-Allow-Origin', '*'); // allow all domains to access the data res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET'); // allow get domains to access the data res.setHeader('Access-Control-Max-Age', 2592000); res.setHeader('Content-Type', 'application/json'); // set the content type to json let apiURL = 'https://api.nasa.gov/planetary/apod?api_key=XXXX'; const response = await fetch(apiURL); // fetching the data from the api const apod = await response.json(); function callApiEveryCSeconds(n) { setInterval(apod, n * 1000); } callApiEveryCSeconds(1); res.end(JSON.stringify(callApiEveryCSeconds)); // return JSON response }); console.log(lastSol()) server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); });

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

0

Sería mejor que ejecutara la API y creara una tarea de trabajo separada que obtenga datos de la API y los almacene en un intervalo de tiempo.

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!