0.0.3 • Published 10 years ago

node_vm_sandbox v0.0.3

Weekly downloads
15
License
-
Repository
github
Last release
10 years ago

node vm sandbox

Build Status Coverage Status Dependency Status

Runs a script string in a vm within a child process.

Example usage:

var sandbox = require('node_vm_sandbox');
sandbox.run({
  script: 'res = "Hello world!"'
}, function(err, res) {
  console.log('Script returned:', res);
});

Usage:

options = {
  script: 'res = "Hello world!"'; // String with JavaScript code. Set `res` with your results.
  env: path.join(__dirname, 'env.js'); // Optional, path to an environment file.
  data: 'abc'; // Optional, will be passed to the environment file.
  timeout: 1000; // Optional, time before the script is terminated, default: 1000.
};
callback = function(err, res) {
  // res will be 'Hello world!'
};
sandbox.run(options, callback);

To illustrate the intended usage of the environment file, this shows how to inject cheerio into the environment:

var cheerio = require('cheerio');

exports.init = function(data) {
  // 'data' is passed from the options
  // This example assumes that data is a HTML page
  return {
    $: cheerio.load(data)
  };
  // Now you will be able to use jQuery inside your script!
};
0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago