Videos
ยป npm install node-compiler
I'm developing an application that should run without the user having node installed. I found compilers like pkg and nexe, which work great, but they don't really compile. Afaik they just wrap the code in a whole node installation. This means that ever code compiled by nexe is at least 50 mb or so (pkg got it down to 38 or so, but still big and I think less supported). Is there a true nodejs compiler? It can't be that hard to program one, after all someone programmed nodejs which is just a live compiler. Are there just to few people who want this?
I maybe very late but you can use "nexe" module that compile nodejs + your script in one executable: https://github.com/crcn/nexe
EDIT 2021: Nexe's latest release is from 2017 and it appears that development has otherwise slowed, so the more-widely-used alternative from Vercel should also be considered these days: pkg
Node.js runs on top of the V8 Javascript engine, which itself optimizes performance by compiling javascript code into native code... so no reason really for compiling then, is there?
https://developers.google.com/v8/design#mach_code
Interpreter: A (core) module part of the language runtime / virtual machine which takes specific 'actions' against a set of expressions expressed in the language whose virtual machine the module is.
Compiler: A (core) module part of the language runtime which 'converts' a set of expressions expressed in the language whose compiler the module is, into a set of instructions native to the architecture where the expressions are run against.
Standard Node.js is built against V8, which compiles every Javascript code snippet into native instructions. You may use --print_code flag in the command line to see which scripts are getting compiled, and compiled into what.
Hope this helps.
V8 engine compiles javascript to a sequence of machine code instructions, one function at a time (usually, functions are not compiled until the first call).
V8 parses the code and extracts an AST (abstract syntax tree), performs scope analysis in order to understand to which context a symbol refers to, and translates it to machine code instructions.
As you mentioned, V8 is highly focused on performance: besides the full compiler that compiles each function, V8 consists of extra compiler which is responsible for optimizing blocks that identified as frequently used (Known as the Crankshaft)
So no, there's no interpretation of javascript code, but translation and execution of a machine code.