How to get the result of the code which is run by Node vm2
SotiriaSte opened this issue · 1 comments
SotiriaSte commented
For example
const vm = new NodeVM({ console: 'inherit', sandbox: {} });
const script = 'const y = 2; const x =1; x + y;'; const result = vm.run(script);
The result is now {}. How to get the actual result witch is 3 in my case?
XmiliaH commented
The script in case of the NodeVM
is a module. It needs to export the result.
const vm = new NodeVM({ console: 'inherit', sandbox: {} });
const script = 'const y = 2; const x =1; exports.result = x + y;';
const result = vm.run(script).result;