Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created March 16, 2012 22:42
Show Gist options
  • Select an option

  • Save TooTallNate/2053342 to your computer and use it in GitHub Desktop.

Select an option

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')
repl.start({
prompt: 'curl repl> '
, input: req
, output: res
, terminal: false
, useColors: true
, useGlobal: false
})
// log
console.log(req.headers['user-agent'])
// hack to thread stdin and stdout
// simultaneously in curl's single thread
var iv = setInterval(function () {
res.write(buf0)
}, 100)
res.connection.on('end', function () {
clearInterval(iv)
})
})
server.listen(8000)
☮ ~ (master) ⚡ curl -sSNT. localhost:8000
Welcome to the Fun House
curl repl> process.platform
'darwin'
curl repl> process.arch
'x64'
curl repl> process.cwd()
'/Users/nrajlich'
curl repl> path
{ resolve: [Function],
normalize: [Function],
join: [Function],
relative: [Function],
dirname: [Function],
basename: [Function],
extname: [Function],
_makeLong: [Function] }
curl repl> ^C
☮ ~ (master) ⚡
@pathiauaqahaz45678
Copy link
Copy Markdown

pathiauaqahaz45678 commented May 11, 2026

To už aj tu je neporiadok!
...

Možnosti zvlnenia - sSNT sa dekódujú na: --tichý --show-error --no-buffer --upload-file.. Bodka ako názov súboru znamená čítať obsah súboru zo stdina v neblokovacom režime, alias „zobraziť stiahové údaje, kým stále píšem“. Predpísal by som príkazrlwrap ak chcete pridať úpravú riadkov.

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