In my application I CreateContext and then RunInContext. I need to add access to only certain Node modules within the Context. I know how to add my own Javascript methods, but get errors when I add Node modules like async and http. How can I do this?
I am using the Sandbox module https://github.com/gf3/sandbox to run child processes
Code
var context = Script.createContext();
context.myOwnFunctions = function() {
//my own javascript
}
context.myNodeFunctions = function() {
//require('async')
//require('http')
/Add some function that use the items I required above
}
var run = Script.runInContext('code to run', context);
require returns the module, so if you do not assign it to something it will not be available.
var context = Script.createContext();
context.myOwnFunctions = function() {
//my own javascript
}
context.myNodeFunctions = function() {
this.async = require('async');
this.http = require('http');
//Add some function that use the items I required above
}
var run = Script.runInContext('code to run', context);