innovationskda.blogg.se

Node js for beginners
Node js for beginners




node js for beginners

So for our purposes, this single-threaded architecture is equivalent to multi-threaded architecture. Since Node.js uses fewer threads, it utilizes fewer resources/memory, resulting in faster task execution. This is how it maintains its non-blocking nature.

  • The event loop tracks blocking requests and places them in the queue once the blocking task is processed.
  • This group of auxiliary threads is called the worker group. There are limited internal threads available.
  • If the request has a blocking operation to perform, the event loop assigns a thread from the internal thread pool to process the request.
  • If not, it processes the request and sends a response.
  • When a request comes in, the loop picks it up from the queue and checks whether it requires a blocking input/output (I/O) operation.
  • This event loop waits for requests indefinitely.
  • Now, the single-threaded “Event loop”-the core component-comes into the picture.
  • Whenever a request comes, Node.js places it into a queue.
  • Node.js maintains a limited thread pool to serve requests.
  • Let’s take a look at each step it goes through:

    node js for beginners

    How node.js process incoming requests using the event loop These threads are defined in a thread pool, and each time a request comes in, an individual thread is assigned to handle it. However, multiple threads are used to process concurrent calls. In a multi-threaded request-response model, multiple clients send a request, and the server processes each one before sending the response back. To understand how this is different from other runtimes, we need to understand how multi-threaded concurrent clients are handled in languages like Java. Node.js uses the “Single Threaded Event Loop” architecture to handle multiple clients at the same time. This adds additional use cases to Node.js’s repertoire, such as accessing internal system functionality (like networking).

    node js for beginners

    The runtime uses Chrome V8 internally, which is the JavaScript execution engine, and it’s also written in C++. Wikipedia defines Node.js as “a packaged compilation of Google’s V8 JavaScript engine, the libuv platform abstraction layer, and a core library, which is itself primarily written in JavaScript.” Node.js is written in C, C++, and JavaScript.






    Node js for beginners