NodeJs VM - save compiled code ... to disk?

From http://nodejs.org/api/vm.html :

JavaScript code can be compiled and launched immediately, or compiled, saved, and launched later . [...] The returned script is not bound to a global object . It is bound before each run, only for this run.

And then in the API there is no method that returns any bytes, nothing. Just a "Script" object.

So, before I politely keep this table under my hands, is there a way I can SAVE the compiled script to disk? I believe that this is ordinary ordinary binary data, maybe a syntax tree or something else.

+4
source share
1 answer

The functions you reference are javascript that runs javascript in a new context (so that it can be safe, have new functions, etc.) ... not saving the precompiled binary ...

If you need information on how to really reload a precompiled script, you can look at the source of node.js. The node.js file itself is precompiled and loaded as a binary file (if you create it using this option). At the same time, it starts node faster.

However, you should keep in mind that there are few advantages for this, unless you think about a specific process (for example, node.js) using the V8 library, which will start / stop / start / stop. etc. The reason is that the V8 library will only compile your script once - and then will execute it as machine code every time after that or as long as the V8 library is running.

Pre-compiling and downloading as a binary file will lead to some significant drawbacks, including the dependencies of your software architecture (even in x86 32-bit from x86_64), etc. Thus, it may not be the best design decision.

+4
source

All Articles