node.js express node-fetch

  node.js, question

The thing is, I get the user information in the routing inside and pass throughreq.session.userInfo = body;Make settings.
However, the session setup failed.
Why?

router.get('/', function(req, res, next) {
 var _id = req.query.UserID;
 if (_id) {
 fetch('https://github.com/')
 .then(function(res) {
 return res.text();
 }).then(function(body) {
 console.log(body);
 });
 res.render('index', { title: 'Express', UserName: 'nickname' });
 bracket
 });

Is fetch asynchronous?

If so, you can’t put the render operation outside fetch.

Code inside also didn’t see you using response.session

= = = = = = = = = modify = = = = = = = = = = = = = = = = = = = = = = = =

Since fetch is asynchronous, then

res.render('index', { title: 'Express', UserName: 'nickname' });

This code should be placed in.then()Inside. Try the following instead

router.get('/', function(req, res, next) {
 var _id = req.query.UserID;
 if (_id) {
 fetch('https://github.com/')
 .then(function(res) {
 return res.text();  //The request processing is finished here, and then the next THEN cannot process res
 }).then(function(body) {
 res.session.user = body
 res.render('index', { title: 'Express', UserName: 'nickname' });
 });
 bracket
 });