Created
August 27, 2014 06:04
-
-
Save stimpy77/3fd438425dadbc5e63e9 to your computer and use it in GitHub Desktop.
REPL for nodeJS as function of app
This file contains hidden or 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
var readline = require('readline'); | |
var trustedEval = eval; | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.prompt(true); | |
rl.on('line', function (cmd) { | |
if (((cmd || '').replace(/\s*/g, '')) === '') { | |
rl.prompt(); | |
return; | |
} | |
if (cmd.toUpperCase() == 'EXIT') { | |
rl.close(); | |
} else { | |
try { | |
console.log(trustedEval('(' + cmd + ')')); | |
} catch (error) { | |
console.log(error.toString()); | |
} | |
rl.prompt(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment