Thursday, 23 January 2020

Is my understanding of how express works correct?

Hi guys, I'm currently building a web server with the express framework for the first time, so I just wanted to know if my understanding of how it works(express and javascript in general) was correct.So, if I were to write some code like this:app.get('/route1', callback1); app.get('/route2', callback2); This is my understanding of what happens when you run this code.​The node runtime creates a separate thread for setting up a queue, and all the callbacks are put there.When a request for a certain route comes in, the corresponding callback is taken off the queue and executed on the main stack if the stack is empty(which is determined by the event loop).Now, here is where I'm kinda confused.If the callback is taken off the queue, how does node run this function again when another requests comes in for the same route?My vague understanding was that the event loop constantly runs the code again and again, but when I thought about it, it doesn't make sense since when you run a regular node script(without asynchronous behavior), the code only runs once then ends.Can anybody help me on this?I'd love to hear an explanation on what I'm understanding wrong.Thanks 😊

Submitted January 23, 2020 at 08:25AM by shuuuumama

No comments:

Post a Comment