-1

I am learning node and it may be silly question but How does node handle multiple users. Like if two users send request at same time, will node create separate instance for both? Assume I am storing username in some variable(name) in node. So if both the users logs in , what value that variable(name) contain? Will it create separate instance and keep both the values?

I am new to node and servers , so please answer in simple language. Thanks in advance

Prakhar
  • 15
  • 3
  • See [this](https://stackoverflow.com/questions/34855352/how-in-general-does-node-js-handle-10-000-concurrent-requests) SO question for more information about the Node Event Loop. Basically, just because Node.js is single-threaded in and of itself, that doesn't mean that it's not using multiple background threads to perform asynchronous operations. That is, the Event Loop runs on a single thread, but most of the I/O is happening on separate threads, with a lot of the workload offloaded to the kernel where possible. –  May 07 '19 at 04:03

2 Answers2

0

The protocol that clients (browser) use to communicate with Node is HTTP.

HTTP is a stateless protocol, meaning that every request sent to your web server must contain all of the information required to satisfy the request. Depending on how your backend application is designed, this information may include the id of the user trying to access the server; perhaps accompanied by an access token or password. It would then be up to your server to verify the credentials on each request and respond in a user-appropriate way.

There's much more to this, but that's the tl;dr.

ctt
  • 1,405
  • 8
  • 18
0

in simple terms, node being single-threaded receives both request at the same time, but it will process each individually and one after the other.

more at https://nodejs.org/de/docs/guides/event-loop-timers-and-nexttick/