Skip to content

doc: vm, run http server in vm by requiring

As user in order to run node code in a vm, you would need to apply some objects to it. This is not quite well documented and may or may not have been reason for a series of issues and SO questions.

This PR would add an example to explain this. It is to some extent controversial and was discussed in a code PR https://github.com/nodejs/node/pull/4955. Issue would have been https://github.com/nodejs/node-v0.x-archive/issues/9211 and this link to SO.

An easier solution would be to use eval(), which I regard as an anti-pattern. Also it uses require('module').wrap(code), which I believe to be a "private" API. I have taken and modified this example from the referenced issues.

/cc @nodejs/documentation

Merge request reports

Loading