Skip to content

Instantly share code, notes, and snippets.

@dhilst
Created March 9, 2018 22:54
Show Gist options
  • Select an option

  • Save dhilst/12bfd64860ecf7518acce6aef49504db to your computer and use it in GitHub Desktop.

Select an option

Save dhilst/12bfd64860ecf7518acce6aef49504db to your computer and use it in GitHub Desktop.
const vm = require('vm');
var data = [];
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
data.push(chunk);
}
});
process.stdin.on('end', () => {
const jsStr = 'var obj = ' + data.join('');
const sandbox = {};
vm.createContext(sandbox);
vm.runInContext(jsStr,sandbox);
process.stdout.write(JSON.stringify(sandbox.obj));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment