Node.js compile the JavaScript that runs on the server?

Posted on

Question :

According to the V8 documentation, it compiles JavaScript for machine code as an optimization strategy.

So, does the JavaScript running on the server via Node.js compile or interpret?


Answer :

Because NodeJS uses the Javascript V8 engine, its code is compiled in time for bytecode of the V8 virtual machine. Before this compilation, it resolves the imports of modules and optimizes the logic of the code.

You can compare NodeJS to a PHP, Python, Java, or ASP.NET server: The code is optimized and compiled into an intermediate assembly language (called bytecode – similar to assembly ).

It is worth remembering that even if NodeJS and other languages have access to some functions of the machine or operating system, it is the virtual machine / interpreter of the language that runs this compiled code. That is, by default Java uses the Java Virtual Machine (JVM), PHP uses the PHP interpreter based on Zend Engine, Python uses the Python interpreter of its distribution (Jython, IronPython, CPython, PyPy) and ASP.NET uses the CLR of the .NET Framework.


It is interpreted and then compiled “on the fly” JIT with V8.

Unlike Java, which compiles the code in bytes, and then the code is compiled to something the machine can understand, NodeJS remains JavaScript, and then the JavaScript is compiled at “runtime” .

Reference: link


Leave a Reply

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