Problem : Given the library method getUser (DB / Local storage fetch asynchronously), fetch all the user objects by ID  in the provided array and return an array consisting of all the requested user objects . It should return the response user object in same order like we are passing the IDs in array

Using traditional callback function with Async approach

Example :

Input : [8,99,1,7,42]

Output :[{“id”:8,”name”:”Marut Kala”},{“id”:99,”name”:”Kumara Ganguly”},{“id”:1,”name”:”Shaamil Eid”},{“id”:7,”name”:”Awf Taheri”},{“id”:42,”name”:”Chandra Saini”}]

Here is the nodejs working code

Note :

  1. getUser should be the callback function that  return the DB user object after search , here we used local array to store user list .
  2. For async purpose we used setTimeout to delay the execution.


Callback | Async | loop | nested callback – NodeJS implementation
Tagged on:             

2 thoughts on “Callback | Async | loop | nested callback – NodeJS implementation

  • July 13, 2017 at 1:06 pm

    fantastic put up, very informative. I wonder why the other experts of this sector don’t realize this.
    You should proceed your writing. I am sure, you have a huge readers’ base already!


Leave a Reply to article writing romantic Cancel reply

Your email address will not be published. Required fields are marked *