Began to study NodeJS, stumbled on the session

//vars var sessionArray; //extention var express = require('express'); var session = require('express-session'); var app = express(); app.use(session({secret:sessionKey,saveUninitialized:true,resave:true})); //app app.get('/superpage',function(request,response){ sessionArray=session; if(sessionArray.datatime){ }else{ sessionArray.datatime = Math.random(); } console.log(sessionArray.datatime); response.end(""); }); 

This part of the code works for me completely. I go to different browsers on one page, and press F5. A different variable appears in the console, browser1 - variable 1, browser2 - variable 2 (as it should be).

Specifically, my application uses a structure where a function is responsible for each page.

 function start(response, extendData1, extendData2){ sessionArray=session; if(sessionArray.datatime){ } else{ sessionArray.datatime = Math.random(); } console.log(sessionArray.datatime); response.writeHead(200, {"Content-Type": "text/html"}); response.end(); } 

about how here

There was a problem, in my case all the variables in the session are the same.

The question is - can anyone diagnose what is written incorrectly?

  • MB is the variable 'sessionArray' to make local? - Bleser
  • @ user235731var sessionArray = session - Bleser
  • I tried, unfortunately there is no effect - user235731
  • Your first code should not work in the same way. Somewhere you were sealed ... - Pavel Mayorov
  • no typos. To take the first example, is it possible to create and use a session without an app there? there is not a single example in the internet (those related to the database are not considered) - user235731

0