Created
March 9, 2017 15:26
-
-
Save jnicklas/1c165a2fdbdb5de9f3d06c28e688f2d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const vm = require('vm'); | |
const repl = require('repl'); | |
function myEval(cmd, context, filename, callback) { | |
let result; | |
try { | |
result = vm.runInContext(cmd, context); | |
} catch (e) { | |
return callback(e); | |
} | |
if(result.then) { | |
result | |
.then((result) => callback(null, result)) | |
.catch((err) => callback(err)) | |
} else { | |
callback(null, result); | |
} | |
} | |
repl.start({prompt: '> ', eval: myEval}); |
Author
jnicklas
commented
Mar 9, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment