What is the architecture of nodejs?

Posted on

Node.Js architecture: You know that Node.js is a runtime environment for executing JavaScript code. But what is it runtime environment? really well. Before nodejs, we use JavaScript only to build applications and run inside of a browser.

So every browser out there has what we call a JavaScript engine that takes our JavaScript code and converts it to code that a computer can understand.

For example,

  • Microsoft ed uses chakra,
  • Firefox uses spider monkey and,
  • chrome uses v8

and is because of these varieties of engines that sometimes JavaScript code can behave differently in one browser or another.

Now a browser provides a runtime environment for JavaScript code. For example, you probably know that in browsers we have the window or the
document object.

These objects allow us to work with the environment in which our code is running.

Now up to 2009, the only way to execute JavaScript code was inside of a browser in 2009.

Also Read:What Is the Best Node.js Framework (and How to Choose It)?

Ryan Dahl the creator of NodeJs, 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 NodeJs.

So similar to a browser node is a runtime environment for JavaScript code. It contains a JavaScript engine that can execute our JavaScript code.

But it also has certain objects that provide an environment for our JavaScript code, but these objects are different from the environment objects we have in browsers.

For example, we don’t have the document object instead we have other objects that give us more interesting capabilities.

Also read: Node vs Go for a REST API | Which is best?

For example, we can work with the file system, listen for requests and a given port and so on.

We can’t do stuff like that inside of a browser right, so in essence, node is a program that includes the v8 JavaScript engine plus some additional modules that give us capabilities not available.

Inside browsers, we can work with the file system or the network and so on., both chrome and node share the same JavaScript engine.

But they provide different runtime environments for JavaScript. Now I’ve seen people conferring node to c-sharp or Ruby or some other programming languages, but these comparisons are fundamentally wrong.

Because nodejs is not programming the language. It’s like comparing a car with an apple by the same token.

Node.Js should not be compared with frameworks such as a spool of meth or rails or Django and so on.

These are frameworks for building web applications, nodejs is not a framework. It’s a runtime environment for executing JavaScript code.

Our other articles:

What exactly is Node.JS | Introduction, Benefits of Nodejs

7 Reasons to use Node.JS


Leave a Reply

Your email address will not be published. Required fields are marked *