As shown in the picture, I used http.get to request the interface and got the returned data. I now want to transfer the avatar to the index page, but after the http.get method is used, iconUrl is undefined. How can I transfer the data returned from the interface to the index page?
iconUrl must be undefined.
It’s a problem with the basic scope of js
Put the sentence res.render into the req.on('end') callback
Scope issue.
Because your variable iconUrl is declared in req.on, when res.render is called, the iconUrl variable in req.on cannot be found. Try putting the declaration of iconUrl in router.get.
Change http.get to a synchronous method or use res.render in the callback. Be careful not to have the same parameter name, just change the alias.
Just write it in the end