Skip to content

Instantly share code, notes, and snippets.

@juliangruber
Last active March 24, 2021 02:00
Show Gist options
  • Save juliangruber/7877042 to your computer and use it in GitHub Desktop.
Save juliangruber/7877042 to your computer and use it in GitHub Desktop.
lightweight node-websocketd

node-websocketd

A lightweight node port of websocketd, originally written in go.

Usage

node-websocketd --port=8080 ./count.sh
var spawn = require('child_process').spawn;
var Server = require('ws').Server;
var Stream = require('websocket-stream');
var argv = require('optimist').argv;
var server = new Server({ port: argv.port });
server.on('connection', function(ws) {
var stream = Stream(ws);
var ps = spawn(argv._[0], argv._.slice(1));
ps.stdout.pipe(stream).pipe(ps.stdin);
stream.on('end', ps.kill.bind(ps));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment