Created
December 29, 2011 23:32
-
-
Save thegoleffect/1536701 to your computer and use it in GitHub Desktop.
[Reference][Snippet][NodeJS]: Remote-accessible REPL server example
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 net = require("net"); | |
var repl = require("repl"); | |
net.createServer(function(socket){ | |
var replserver = repl.start("prompt > ", socket); | |
// You must explicitly give the repl client access to variables via replserver.context variable. | |
// The following line is intended for educational purposes only. DO NOT USE in practice. | |
replserver.context = exports; // DANGER: This gives repl client access to ALL global variables of this program. | |
replserver.context.myvar = "stuff"; | |
}).listen(5000); // Adjust port number as needed | |
/* | |
To connect to the repl: | |
$ rlwrap telnet hostname 5000 | |
The program rlwrap gives telnet access to the readline library. This lets you access command history via arrow keys. | |
Node.js's repl library provides some niceties. The most useful is the ".exit" command. | |
If you enter that command into telnet, it will gracefully exit. ^D won't always work. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment