Skip to content

Instantly share code, notes, and snippets.

@thegoleffect
Created December 29, 2011 23:32
Show Gist options
  • Save thegoleffect/1536701 to your computer and use it in GitHub Desktop.
Save thegoleffect/1536701 to your computer and use it in GitHub Desktop.
[Reference][Snippet][NodeJS]: Remote-accessible REPL server example
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