Last active
October 6, 2016 05:49
-
-
Save rgbkrk/bb91723f3e340317cea7a105573143ad to your computer and use it in GitHub Desktop.
Node REPL
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 readline = require('readline') | |
const vm = require('vm') | |
const sandbox = vm.createContext(Object.assign({}, global)) | |
const rl = readline.createInterface(process.stdin, process.stdout) | |
rl.setPrompt("> ") | |
rl.prompt() | |
rl.on('line', (line) => { | |
// TODO: buffer lines until command complete | |
try { | |
console.log(vm.runInContext(line, sandbox)) | |
} | |
catch(err) { | |
console.error(err) | |
} | |
rl.prompt() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment