Home > Back-end >  Are Runtime environments and Compilers/Interpreters the same?
Are Runtime environments and Compilers/Interpreters the same?

Time:10-24

I'm just getting started with Node.js and I have quite a bit of background in Python and C . I got to know that Node.js is a runtime environment but I'm having a rough time understanding what actually it does to a code that makes it different from a compiler. It would be better if someone can explain how specifically runtime environments differ from typical compilers and interpreters.

CodePudding user response:

A compiler is a program that converts code from one language to another. In Java for example we have a the java compiler javac that you can run on your .java files to compile your code intointo platform independent java file (can be understood and executed by any machine). Since you are new to JavaScript, you will encounter the transpilers (like babel) that turns your next generation JavaScript code into a legacy JavaScript code that can be handled by all browsers (even old ones). A runtime is a more vague concept. It can go from being a set of functions to run a compiled code on a specefic operating system to being the whole environment in which your program runs. For the case NodeJS, it's the environment on which you can run a JavaScript program out of the browser. It took the V8 Engine of Chrome that runs JavaScript on the Chrome browser and made it available everywhere. That's how JavaScript moved from being a Client side Programming Language that runs only on the browser to a server side Programming Language that can run on servers equiped with the runtime environment NodeJS.

CodePudding user response:

A few simple points that might help:

  1. C/C code will be compiled by the C/C compiler into the machine code and will not need any runtime environment to run (mostly, except the run-time libraries)

  2. Python code needs Python interpreter to execute it. As you say you have background in C /Pythons you must be familiar with all these nitty-gritty

  3. JavaScript was meant to run in the browser and it does mostly, however some smart folks thought of running it outside the browsers and they created the JavaScript execution engine (which is kind of stand alone JavaScript executor) and Node.js is just one of them. It simply runs the JavaScript code outside browser on it's own. The execution is still interpretation of JavaScript code so it is just an interpreter with hell lot of support functions for managing the runtime dependencies, package management, etc.

  • Related