Skip to content

Instantly share code, notes, and snippets.

@stimpy77
Created August 27, 2014 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stimpy77/3fd438425dadbc5e63e9 to your computer and use it in GitHub Desktop.
Save stimpy77/3fd438425dadbc5e63e9 to your computer and use it in GitHub Desktop.
REPL for nodeJS as function of app
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