If given a sandbox object, the vm.createContext() method will [prepare that sandbox][#vm_what_does_it_mean_to_contextify_an_object] so that it can be used in calls to vm.runInContext() or script.runInContext().
If given a sandbox object, the vm.createContext() method will [prepare that sandbox][#vm_what_does_it_mean_to_contextify_an_object] so that it can be used in calls to vm.runInContext() or script.runInContext(). Inside such scripts, the sandbox object will be the global object, retaining all of its existing properties but also having the built-in objects and functions any standard global object has. Outside of scripts run by the vm module, sandbox will remain unchanged.
If sandbox is omitted (or passed explicitly as undefined), a new, empty contextified sandbox object will be returned.
The vm.createContext() method is primarily useful for creating a single sandbox that can be used to run multiple scripts. For instance, if emulating a web browser, the method can be used to create a single sandbox representing a window's global object, then run all <script> tags together within the context of that sandbox.
the given sandbox
vm.createContext([sandbox])
0.11.7
Creates a new script
Creates a new script
The JavaScript code to compile.
the optional options
vm.createScript(code[, options])
Returns true if the given sandbox object has been contextified using vm.createContext().
Returns true if the given sandbox object has been contextified using vm.createContext().
the sandbox
true if the given sandbox object has been contextified using vm.createContext().
Runs the compiled code contained by the vm.Script object within the given contextifiedSandbox and returns the result.
Runs the compiled code contained by the vm.Script object within the given contextifiedSandbox and returns the result. Running code does not have access to local scope.
The JavaScript code to compile and run.
A contextified object as returned by the vm.createContext() method.
the optional options
script.runInContext(contextifiedSandbox[, options])
The vm.runInDebugContext() method compiles and executes code inside the V8 debug context.
The vm.runInDebugContext() method compiles and executes code inside the V8 debug context.
The JavaScript code to compile and run.
vm.runInDebugContext(code)
First contextifies the given sandbox, runs the compiled code contained by the vm.Script object within the created sandbox, and returns the result.
First contextifies the given sandbox, runs the compiled code contained by the vm.Script object within the created sandbox, and returns the result. Running code does not have access to local scope.
The JavaScript code to compile and run.
An object that will be contextified. If undefined, a new object will be created.
the optional options
vm.runInNewContext(code[, sandbox][, options])
Runs the compiled code contained by the vm.Script within the context of the current global object.
Runs the compiled code contained by the vm.Script within the context of the current global object. Running code does not have access to local scope, but does have access to the current global object.
The JavaScript code to compile and run.
the optional options
script.runInThisContext([options])
The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.
https://nodejs.org/api/vm.html