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

199
Views
How to use async.eachSeries in nodeJS?

I want to iterate through a list of items in a synchronous manner and use the result of each step in the next step. I can someone correct/suggest the code logic which I am using?

const async = require('async')

async.eachSeries([1, 2, 3, 4, 5],
  function downloadChunk (chunkID, asyncCallback) {
    console.log(chunkID)
    const result = `This is a result from ${chunkID} call and should be used somewhere in ${chunkID + 1}`
    // How should I pass this result to next step
    asyncCallback()
  },
  function complete (err) {
    if (err) console.log('Error: ' + err)
    console.log('this is the end. All the variables have been used')
  }
)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can simply create a variable outside the async.eachSeries like so:

const async = require('async')
var result = null;

async.eachSeries([1, 2, 3, 4, 5],
    function downloadChunk (chunkID, asyncCallback) {
        console.log(chunkID)
        console.log('Result from previous call', result);

        // reassign new value to the result
        result = `This is a result from ${chunkID} call and should be used somewhere in ${chunkID + 1}`

        asyncCallback()
    },
    function complete (err) {
        if (err) console.log('Error: ' + err)
        console.log('this is the end. All the variables have been used')
    }
)
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!