Node.js Architecture
So! In the last article we have learned that a Node is a runtime environment for executing JavaScript code. But what is the runtime environment means?
Well! Before we knew JavaScript only to build applications only to run inside our browser. So every browser out there has what we call is a JavaScript Engine that takes the JavaScript code and converts it into a code that a computer can understand.
For Ex: – Microsoft uses e chakra, Firefox uses SpiderMonkey and Chrome uses V8. And because of these varieties of these engines that sometimes JavaScript code can behave differently in one browser or in another. Now a browser provides runtime environment for JavaScript code. For example you probably know in browsers we have the window or a document objects these objects allow us to work with the environment in which our code is running.
Now up to 2009 only way to execute a JavaScript code was inside of a browser. In 2009 Ryan Dahl came up with a brilliant idea, he thought it would be great to execute JavaScript outside of a browser. So he took Google’s V8 engine which is the fastest JavaScript engine out there and embedded it inside a C++ program and called that program as Node.exe.
So similar to a browser Node is a runtime environment with JavaScript code. It contains the JavaScript engine that can execute a JavaScript code. It contains the JavaScript engine that can executes a JavaScript code.
But it also has certain objects that provide an environment for a JavaScript code. But these objects are different from the environment objects we have in browsers. For Ex: We don’t have the document object instead we have other objects that gives us more interesting capabilities. For example we can work with a file system, listen for request and give reports and so on.
We cannot do stuff like that easily inside of a browser right! So in a sense Node is a program that includes a V8 JavaScript engine plus some additional modules that gives us capabilities not available inside browsers. We can work with the file system or the network and so on.
Most chrome and Node share the same JavaScript engine but they provide different run time environment for JavaScript’s. Now there are people who compare node to C# or ruby or some other programming languages. These comparisons are fundamentally wrong because Node is not a programming language.
It is like comparing a car with an apple. By the same token Node should not be compared between frameworks such as ASP.NET or Django and so on.
These are frameworks building web applications, Node is not a framework! It is a runtime environment for executing JavaScript code.
Visit: Hostripples