Top Contribution
bendrucker

You want the vm core module from Node: https://nodejs.org/api/vm.html

> The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.

You can provide a global context which gives you control over built-ins like console, process, require, timer functions, etc. It’s not secure but it’s convenient if you’re after isolation for testing.

If you get super clever you can run an actual sandbox: https://github.com/patriksimek/vm2

bendrucker

You want the vm core module from Node: https://nodejs.org/api/vm.html

> The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.

You can provide a global context which gives you control over built-ins like console, process, require, timer functions, etc. It’s not secure but it’s convenient if you’re after isolation for testing.

If you get super clever you can run an actual sandbox: https://github.com/patriksimek/vm2

bendrucker

it’ll kinda work but require does a lot of work and resolving deps would get tricky

bendrucker

npm is pretty dependent on a module resolution system for dependencies

bendrucker

i don’t actually use it but i do use the pieces, a la mercury

bendrucker

unlike some other packaging tools the kiddies are fond of these days which are more complicated than code that launched rockets to the moon

bendrucker

But yes, normally just using global is the move since it’s consistent w/ the browserify contract of compiling your node code for the browser

bendrucker

Extracted from some crazy code gen that browserify-shim was using