I'm dipping my hands on nodejs with express on trying to make my first application on this platform. On this code on the image, I am from the post request, I am trying to check if the userData sent to me is already registered. If not it will register the user. To minimize Callback, I am going to use Events to tell me if the functions I call are done. In this case, if checkUser function property on the right of the image, if db found the user, it will emit the userAuthenticated
event written on the left. If it's not it will write the user and emit the userRegistered
event.
The problem is that the sometimes it works, sometimes it does not. This is my first time writing async functions on node, and I am stumped on how it functions.
- the code - http://prntscr.com/9h2qr2
- Error in Browser - http://prntscr.com/9h2szw
- Error in Node - http://prntscr.com/9h2t81