This post is going to talk about V8 Engine and Introduction to NodeJS
Accepts instructions in a particular language (eg: IA-32, X86-64, ARM, MIPS…). We need to give instruction to a processor on a computer in the language it understands. The microprocessor inputs those instructions and executes them.
Machine Code (or Machine Language)
Programming languages understood by computer processors. Every program that runs on a computer is compiled (converted) into the machine language using the respective compiler. All code eventually converts to machine code so that the machine can carry out the job.
Eg: Rhino, Spidermonkey, V8…etc
The V8 Engine
Greet() is not a valid JS code as per ECMA standards. There’s no corresponding C++ code in V8 engine for Greet() function.
What we can do is that write our own C++ program with Greet() definition and embed V8 into this program. So now when someone will call Greet() function in JS and pass it through our custom made engine (our C++ program with V8 embedded), it will invoke the Greet() function defined in our C++ program.
So what is NodeJS?
We’ve seen that V8 is designed so that we can embed other C++ programs and make features and things we can do in C++ available to JS. This is what Nodejs is. Nodejs is a C++ program with V8 embedded that has added a wealth of great features that make is suitable to be a server technology.
Let’s look at some of the open source code inside the Engine (V8 plus C++ program).
Here we can see definitions of functions such as Print() which are natively not available in EcmaScript. Whenever the Print() function is invoked in nodejs, it will create a callback and the function will be executed.
Similarly, we can add our own implementation of different new functions in C++ inside V8 allowing it to be understood by Node.js.
That’s the basic working of V8 Engine and how it helps in execution of JS code on the server side (nodejs).
Programming Enthusiast. Peace Lover. Interested in poetry and literature