In order to have a proper mental model of Nodejs, we first have to have an accurate understanding of it's core, Heart of
Nodejs, It's V8 Engine
A Tiny Machine.
as we know, each machine either (computer, laptop, mobile, etc...) has something called
processor and it is responsible to doing the calculation all the time.
It is exist in your machine, and you can hold it, it is physical.
Micro-Processor speaks a language, Not all micro-processors are the same.
They don't speaks the same language, there are different ones like (x86-64, IA-32, ARM, MIPS, ...)
Programming Languages spoken by computer processors
Every program you run on your computer has been compiled into a
machine language, must to be compiled into it; because the
machine has all responsibility to run your programs
and sometimes it converted to another different programming languages (Intermediate Language), so that your program can run on different computers, many different processors for example.
Writing with machine code like this
so hard; because it is so close to micro-processor.
this language which you seen it is for specific micro-processor language and there others for micro-processors as we said.
Machine code it is not abstracted at all, you know everything, you control on everything in your machine
the more abstraction layers, the less controlling. means the high-level language care about many things that you may not know it at all, and low-level language you are almost controller for everything.
Assembly came in after Machine Code, so close as well, but more easier to
NodeJS is written by C++ means, Nodejs is a program is written in C++
v8.h header file (
deps/v8/include/v8.h in the Nodejs source tree), which is also available online.
libuv: The C library that implements the Nodejs event loop, its worker threads and all of the asynchronous behaviors of the platform.
Why NodeJS written in C++? because V8 itself is written in C++ too!
It convert your code into Native Machine Code!
because of that V8 is Fast! V8 see what your micro-processor of your system and compile code depend on that.
Engine Handle so many things:
The V8 engine gets its speed from the Just in Time (JIT) compilation of JS code to native machine code. The ignition interpreter, a key component of V8, compiles the JS code and generates non-optimized machine code. On runtime, the machine code is analyzed and re-compiled for optimal performance. This optimization is handled by the TurboFan and Crankshaft components of V8.
Your code may have many issues may cause bad performance, but to know that, you should know how V8 compile your code correctly. read
V8 engine is distinct from other JS engines as it directly converts scripts to machine code without producing intermediate code.
at the end, There are many years.. many many years to implement something like that, so many efforts to produce something amazing like that
the team of project V8 was consist of 12 engineers!