The Node Programming Model

Colin J. Ihrig · Apress eBooks · 2013

Before trying to write any meaningful Node applications, it's important to understand what's going on under the hood. Probably the most important thing to understand is that JavaScript—and Node by extension—is single threaded. This means that Node applications can do exactly one thing at a time. However, JavaScript can give the illusion of being multithreaded through the use of an event loop . The event loop is used to schedule tasks in Node's event-driven programming model. Each time an event occurs, it is placed in Node's event queue. In each iteration of the event loop, a single event is dequeued and processed. If, during processing, this event creates any additional events, they are simply added to the end of the queue. When the event is completely handled, control is returned to the event loop, and another event is processed. These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Read the paper · More papers on PaperTik