Event Loop
Node.js is a single threaded system by design. If you don’t know what threads or what even a single one will do. No problem. Just keep the following idea in mind when working with Node.js
Node.js can only do one thing at any given time.
This means that you can not do two things at the same time, one has to happen before or after another.
Synchronized Programming: Each of the lines of the program have to execute one after another. This means you can easily run into the problem of blocking your entire program if you are doing something that requires the use of the entire thread.
Unsynchronized or Asynchronous Programming: None of the lines of the program need to run in a specific order. This means that your program can run at different time.
Why is time important?: Time is important to both sync and async code, this is due to the nature of how the code is executing.
Now the reason why time matters to Node.js is because node uses both sync and async functionality when executing code. If you create a program that executes in sequential order all of your code will have to execute line by line. If you create a program that executes in unsynchronized manner then the code can run at different times and not be dependent on other parts of the program.
What’s better async or sync? This will depend on what type of program you are writing, Node.js provides you with the functionality to write both at the same time.
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More