Vm2: What does console: 'redirect' mean

Created on 4 Feb 2017  ·  3Comments  ·  Source: patriksimek/vm2

I wanted to know what you mean by "redirect to events" when using the redirect option for console in NodeVM. I have always used the sandbox method, of just attaching a console object with its own methods, however I wanted to know if there was an alternative cleaner solution

discussion

Most helpful comment

It's working like this:

const vm = new NodeVM({
    console: 'redirect'
});

vm.on('console.log', (msg) => {
    console.log('REDIRECTED:', msg);
})

vm.run("console.log('hello');");

You can listen for those events:

  • console.log
  • console.info
  • console.warn
  • console.error
  • console.dir
  • console.trace

All 3 comments

It's working like this:

const vm = new NodeVM({
    console: 'redirect'
});

vm.on('console.log', (msg) => {
    console.log('REDIRECTED:', msg);
})

vm.run("console.log('hello');");

You can listen for those events:

  • console.log
  • console.info
  • console.warn
  • console.error
  • console.dir
  • console.trace

Awesome thanks!

Thanks! maybe we can add this to README or other documentation?

Was this page helpful?
0 / 5 - 0 ratings