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

225
Views
fs.writeFileSync escribe solo cierta cantidad cada vez, no todos los datos. JavaScript

Tengo un problema, estoy ejecutando un programa que ejecutará cada objeto a través de foreach y escribirá los datos dentro del archivo json, pero siempre se detiene en algún punto, cada vez que es diferente. No me da ningún error, simplemente se detiene como lo haría normalmente. Y terminé con 300 objetos en lugar de los 1400 que quería. ¿Alguna ayuda?

 function t (){ var jsonData = JSON.parse(fs.readFileSync("./list.json")); jsonData.forEach((element) => { request('https://api.elrond.com/accounts/'+element.address+'/tokens/count', function (error, response, html) { if (!error && response.statusCode == 200) { try{ var arr = JSON.parse((cheerio.load(html))('html').text()) } catch(err){console.log(err)} data = { address: element.address, ESDT_count: arr } console.log(data) try{ var myObject = JSON.parse(fs.readFileSync("./list1.json")); myObject.push(data); var newData = JSON.stringify(myObject); fs.writeFileSync("./list1.json",newData); } catch(err){console.log(err)} }}) }) } t();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

lo solucione con retraso

 async function a () { data.forEach(async (person,i) => { setTimeout(() => { request('https://api.elrond.com/accounts/'+person.address+'/tokens/count', async function (error, response, html) { if (!error && response.statusCode == 200) { try{ var arr = await JSON.parse((cheerio.load(html))('html').text()) } catch(err){console.log(err)} console.log(arr) var data ={ address: person.address , staked: arr } var myObject = JSON.parse(fs.readFileSync("./list1.json")); myObject.push(data); var newData = JSON.stringify(myObject); fs.writeFileSync("./list1.json",newData); }}) }, i * 1000); }); } a()
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!