Node Fundamentals (5 Part Series)
This is a series of posts that will illustrate the what, why and how of Node. I'll be sharing my learnings from a course on Advanced NodeJS by Samer Buna offered on PluralSight. Any code samples tagged or attached will be available at the following repo.
- v8, Default, Single-Threaded
- Chakra by Microsoft, powers Edge browser
- Shipping - Available by default
- Staged - Not quite ready yet. flag
- In-Progress - Less stable.
You can see the list of all group features by
node --v8-options | grep "in progress" node --v8-options | grep "staged"
Node is more than a wrapper for v8, it provides APIs for working with the file system, operating system, binary data, networking and much more. It mainly constitutes of the following components.
Node v8 uses v8 C++ API. So, node API eventually executes C++ code using V8 object and function templates.
When node is done waiting for IO or timers, it usually has callback functions to invoke back to. When it's time to invoke these callbacks, node passes control from
libuv to the v8 engine. When v8 executes the callback, it passes control to Node itself.
libuv is a C library developed for Node, but now it's used by Rust, Julia and others. It's used to abstract the non-blocking I/O operations. It provides a consistent interface across many operating systems.
It handles operations on the file system, TCP/UDP sockets, child processes, and others.
libuv includes a thread pool to handle what can't be done asynchronously at OS level.
libuv also provides node with Event Loop.
Apart from v8 and libuv, node has a few more dependencies.
http-parser: Library for parsing HTTP messages. It works for requests and responses, works with a very small memory footprint.
c-ares: Enables performing asynchronous DNS queries.
OpenSSL: Mostly used in
cryptomodules. Provides the implementation for many cryptographic functions
zlib: Used for fast streaming compression and decompression interfaces.
Level up every day