Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How can I pass the variables exported to the second middleware (pass elements and data_fsq from 1.js to 2.js)? how can I callback the elements
How can I pass the variables exported to the second middleware (pass elements and data_fsq from 1.js to 2.js)? how can I callback the elements and data_fsq when they receive the data from getData() function and use it in 2.js?. I keep getting undefined for both elements, and data_fsq when I try to use them in 2.js.
1.js
2.js
1 const router require('express' ).Router); 2 var fetch require('fetch-retry) 4 let data fsq ; 5 let elements -; 7 getdata(url) then (data => { router.get ('/data', function (req, res) 10 res.json (data); elements data 12 13 14 15 16 17 18 19 20 21 for (let element in data) { http -www.url,com fetch(http, f retries: 1 J) then (res if (res.ok) { return res.json(); else t throw new Error('err); 23 24 25 26 27 28 29 30 31 32 7) then(body data_fsq[data[element].id] body.items; router.get( /api/data/$fi}', function (req, res) { res.json (body) 7) .catch((error)->{ console. log ('error loading the data for '-data_fsq [element. name); 1) 34 35 36 37 module.exports 38 39 40 router: router, data_fsq: data_fsq, // undefined elements: elements//undefined 41 42
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started