Hi, I have a use case in node.js (express.js) and need help in implementing this feature as it is getting very complicated. With very less experience in node.js and npm, I am running into issues anf trying to find right approach and node packages or libraries that could simplify my coding. UseCase: I have this dynamic JSON from front end- University JSON Object -> has Schools Array -> Each school has dynamic sized Depts Array.
*{* *University:* *{* *univName : “Loyolla” , * *location : “KT”,* *Schools :[* *{* *schoolname: "ABC" , location: "x" , * *Depts : [ {deptname: "dep1" },{deptname: "dep2" }]* *},* * {* *schoolname: "BCD" , location: "y" , * *Depts : [**{deptname: "dep1" },{deptname: "dep2" },{deptname: "dep3" }]* *}* *]* *}}* I transform this json into another JSON format and create multiple JSON Objects out of it. For each dept + school combination along with common univ info, we have separate object. In above ex, I will have 5 objects. For simpliicity sake, assume, same format of JSON but 6 objects, but only 1 school + 1 dept infomation + common univ info. Ex, of just 1 object, *University:* *{* *univName : “Loyolla” , * *location : “KT”,* *Schools :[* *{* *schoolname: "ABC" , location: "x" , * *Depts : [ {deptname: "dep1" }]* *}* *}* *]* *}}* Now, I have to POST these set of JSON objects ( say 5 here) to some service via promise ?? Earlier we were planning to have just 1 JSON object for all this University Info and send it over API (like 1st json with full info)but now, they demand array of objects be created, for each dept value + school + univ, so many JSON objects be POST'ed. I am highly confused how to achieve all this. For creating 1 object, I use request API ( request-promise). Body in Options in request contains our JSON object. *var options = {* * method: 'POST',* * uri: 'http://api.posttestserver.com/post',* * body: {* * some: 'payload'* * },* * json: true * *};* Now, instead of 1 object, I have array of objects. So body/payload is slightly different each time and I will need to call same API over n times. Do I need to call request promise in 'for' loop? , I was looking at different packages, I do not think promise-arrays is not right package ? Any suggestions. Another thing,, even simple 1 object creation, is nested under many promises which I do not prefer but not - using promises was causing asyn issues. it makes GET call to API to fetch some IDs, then sets some JSON object, POSTs that JSON, again get some results, read results, and sets some key/values of above json dynamically based on results. So I have 5-6 promises already nested and calls are dependent on previous calls results. So how can i simplify my code? Please suggest if there are npm mackages that I can use. -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. To post to this group, send email to nodejs@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/a1db9d80-8764-493c-b0fa-8ecb69daaee7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.