My question is that I am trying to develop a NodeJs REST service using which people can Register themselves on my site.My registration flow is something like this:
1.Check if any user exits with the same email
If the user exists , send a response to tell that user already exists
If user does not exists, create a user object with the entered details.
4.Now Insert this into DB.
- Send a response that the user is been registered.
Now let's say I have two users "A" and "B" , they entered same email ids , Now let's say User A and B both reaches a point where my code will check if the user exits or not, they both will get that user does not exists and their flow will move towards to create the object and create a object on DB. Now in this case if there is an synchronised block as we have in Java , we can prevent these two cases to create object at the same time, but in NodeJS how can I make this happen? and how to avoid this race round situation??
Does NodeJs being single threaded and having a common stack will prevent this from happening? or if there is any other way to do this in NodeJs? I am very new to NodeJs , I am sorry if I have mentioned something wrong.