Node VM run in context

node v10.21.0
version: 3.0.0
// create 'myglobal' in global space: (function(){myglobal='my global'})() // access myglobal from eval - works eval("console.log('1 myglobal='+myglobal)") const vm = require('vm') const script = new vm.Script("console.log('2 myglobal='+myglobal)"); // run script in the global context - works script.runInThisContext() // run the same script in a new context - fails: script.runInNewContext()

no comments

    sign in to comment