I have nodejs app, I using typescript and Express server and express-session.
I have also routing function that get request from the client and response.
private async changeVis(req: express.Request, res: express.Response) {
Let mySession=._deepClone(req.session['blah']);
MyModule.changeViz(mySession).then(function(myRes){
req.session["blah"] = myRes;
console.log('before res.json');
res.json("");
console.log('after res.json');
});
My problem is, that the line
res.json("");
take somthing like 5 seconds, the delta between the time 'before res.json' appear and 'after res.json' appear is plus minus 5 seconds.
Now, when I not use session and the function is like :
private async changeVis(req: express.Request, res: express.Response) {
MyModule.changeViz().then(function(){;
console.log('before res.json');
res.json("");
console.log('after res.json');
});
there is no delta, 'after res.json' appear immediately after 'before res.json'.
I try to add res.end(), but it's not help.
Someone can help?
Because you declared the function to be async. your res object will wait until all of the processes in the function will end . You can either make all your other functions after res.end(); Or remove the async from the function