Tuesday 12 April 2016

Could someone explain to me how multiple sessions work in Node?

I'm brand new to Node, trying to understand how multiple users could ever use a node server simultaneously.Suppose I have some processing stream "parseAndHandle" which is part of my controller. Every time a client sends a request I want to stream it through parseAndHandle.I could do something like:server = http.createServer(function(req, res) { if (req.method === "POST") { return req.pipe(parseAndHandle).pipe(res); } }); server.listen(process.argv[2]); which should work OK, assuming that I only have one user at a time. But if Joe logs on, sends a request, and Mike logs on and sends another before Joe's has finished returning, how can I be sure that Joe won't get Mike's response?I guess it comes down to my understanding of what a stream is. When information is passed through parseAndHandle, is it all handled by a single object named parseAndHandle reading every chunk of data passed to it by anything which is piping into it, or are instances of parseAndHandle created each time on the fly.What's going on under the hood?Any resources appreciated, perhaps I'm missing something fundamental here. I greatly appreciate all advice!

Submitted April 12, 2016 at 11:48PM by Yamochao

No comments:

Post a Comment