[英]User specific global variable in Node.js
my program looks as follows:我的程序如下所示:
var globVar=[];
function1(usr){
//calculations with globVar
}
function2(usr){
//calculations with globVar
}
app.post('/', function(req, res) {
var formString = req.body.filter1;
globVar.push(formString);
usr= req.connection.user;
function1(usr);
function2(usr);
res.redirect('/');
});
req.connection.user comes from nodeSSPI module. req.connection.user 来自 nodeSSPI 模块。 I need to make this globVar user specific so it doesn't mixed up when users runs this app concurrently.
我需要让这个 globVar 用户特定,这样当用户同时运行这个应用程序时它就不会混淆。 Now it works well but only for single user:)
现在它运行良好但仅适用于单个用户:)
Thank you for your consideration on this matter.感谢您对此事的考虑。
I've been looking at what seems like the same problem and my solution was to simply use cookies, and set a variable within the cookies client-side.我一直在研究似乎是同一个问题,我的解决方案是简单地使用 cookies,并在 cookies 客户端中设置一个变量。
In my case the problem was setting language choice permanently for each user and that was simplest.在我的例子中,问题是为每个用户永久设置语言选择,这是最简单的。
This guide helps: https://www.tutorialspoint.com/expressjs/expressjs_cookies.htm本指南帮助: https://www.tutorialspoint.com/expressjs/expressjs_cookies.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.