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

219
Views
fs.writeFileSync write only certain amount every time, not all data. Javascript

I have a problem, am running programm which will run every object throug foreach and write the data inside json file, but it always stop at some point, everytime its different. It doesnt give me any error, it just stop like normal would. And i ended up with 300 objects instead of 1400 i wanted. Any help?

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

i solved it with delay

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!