Skip to content

johvik/node_vm_sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!
};

About

Runs a script in a vm within a child process

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published