Skip to content

Instantly share code, notes, and snippets.

Created March 16, 2012 22:42
Show Gist options
  • Save TooTallNate/2053342 to your computer and use it in GitHub Desktop.
Save TooTallNate/2053342 to your computer and use it in GitHub Desktop.
Running a node.js REPL over `curl`
* Requires node v0.7.7 or greater.
* To connect: $ curl -sSNT. localhost:8000
var http = require('http')
, repl = require('repl')
, buf0 = new Buffer([0])
var server = http.createServer(function (req, res) {
res.setHeader('content-type', 'multipart/octet-stream')
res.write('Welcome to the Fun House\r\n')
prompt: 'curl repl> '
, input: req
, output: res
, terminal: false
, useColors: true
, useGlobal: false
// log
// hack to thread stdin and stdout
// simultaneously in curl's single thread
var iv = setInterval(function () {
}, 100)
res.connection.on('end', function () {
☮ ~ (master) ⚡ curl -sSNT. localhost:8000
Welcome to the Fun House
curl repl> process.platform
curl repl> process.arch
curl repl> process.cwd()
curl repl> path
{ resolve: [Function],
normalize: [Function],
join: [Function],
relative: [Function],
dirname: [Function],
basename: [Function],
extname: [Function],
_makeLong: [Function] }
curl repl> ^C
☮ ~ (master) ⚡
Copy link

mk-pmb commented Mar 28, 2022

nginx will ensure it will behave itself, as in, it will strictly speak standard HTTP to your web app. This is a protective feature. The idea in this thread uses a non-standard protocol and disguises it as HTTP, very thinly. The disguise breaks as soon as you insert a component that expects real HTTP.

Edit: You might get away with HTTP UPGRADE somehow, but it will probably be a bit more complicated.

Copy link

Do you have any idea about how to UPGRADE it?

Copy link

On Ubuntu 20.04, curl takes a lot of CPU resources (more then 25%) to run this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment