If you’re a developer, you already know that node.js is a runtime environment and how it was developed by binding C++ and V8 engine. But how do we visualize it?
Being from non-tech background I kept thinking what is actually a runtime environment?, I had this vague idea seeing the name, but I searched about it, because I wanted to have the clear picture.
• Basically To execute a code you need collections of software and hardware components. Why? Because software tells you how to execute that code and hardware actually does that execution.
• The Runtime Environment is just abstraction layer between code, Os and Hardware components which provides essential services and allows programs to run consistently across different platforms i.e runtime gives us pre-written code that acts as a functionality so we don’t have to deal with OS or hardware directly!
• Without those services we would actually have to manage memory system, handle the CPU instructions, andd deal with the networking protocols ourselves, doesn’t seem practical right?!!
Now, we should know what are the key components involved in this. Just a little summary of what I wrote above:
• An execution engine (Interpreter):
Computer does not understand JS, only 0s & 1s. So, you need something that reads our code, convert it into 0s & 1s, and finally run it. That’s what we have execution engine for, and there are actually 2 ways to do it. But do that search on you own.
• Runtime Libraries:
Collections of pre-written code (APIs), which provides basic, common functionality to the program.
• Memory management system:
RTE manages how memory gets allocated ( Stack / Heap ) and deallocated during execution and most of the time it also includes garbage collection to prevent memory leaks.
• Core system interface:
This is a interface for the OS and the Hardware, that handles scheduling and exception tasks.
Well, We all have been using a runtime environment way before we started with the JavaScript, Web Browser.
It’s a Runtime environment for the frontend Javascript application.
Top comments (4)
This topic is an important one.Because every beginner gets stuck at this place:
-> compiler vs interpreter
or
-> how browser engine is different from python like lang
-> why one lang is slow and another is fast
etc...
For me, I understood the topic with this analogy:
Suppose, you are a businessman and want to make a deal with a foreign client.
But, you don't know his language.
Here, you got 2 options:
1) You hire an interpreter(same name and task), a person who translates your words on the spot to your client.
But, its slow because he needs to listen to each line, understand it and then explain it to you.
2) OR you can learn the language yourself and then directly talk to the client and make a deal.
Here, the problem is, it takes time to learn the language.
Similarly, interpreter is a piece of software between the programmer and the computer that on the spot runs and translates each line for us into zeros and ones.
Here, the interpreter is also taking some memory space along with our program and little bit slow because of the line by line explaining nature.
And compiler converts all our code into computer's lang (0s and 1s) beforehand into a file called binary or executable.So, it takes time to convert it. But, once done, you don't need the middle man anymore. So, the binary takes less space in memory and computer can run it directly, so fastly.
This is those 2 ways are for executing the program. I am glad that i read about it, cause now the picture about the runtime environment is clear. Thanks for your explanation.
welcome 👍!
if you're reading this, and if there's something i should know, let me know!
Some comments may only be visible to logged-in visitors. Sign in to view all comments.