Skip to content

Commit

Permalink
updated docs to fit stream interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Nov 10, 2012
1 parent f8eb5df commit 78c968b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions README.md
Expand Up @@ -8,14 +8,29 @@ The first thing you need is to setup a spy inside your program

``` js
var spies = require('spies');
var net = require('net');

spies(9999, function(spy) {
spy.on('echo', function(value) {
spy.log(value);
net.createServer(function(socket) {
var spy = spies();

spy.on('echo', function() {
spy.log(Array.prototype.slice.call(arguments));
});
spy.on('load-avg', function() {
spy.log(require('os').loadavg());
});

socket.pipe(spy).pipe(socket);
}).listen(9999);
```

As you can see `spy` is simply a readable and writable stream so you can pipe to any kind of stream (like a websocket)

You can use the `spies.listen` helper if you just want to listen using a tcp server

``` js
spies.listen(9999, function(spy) {
// attach commands here
});
```

Expand Down

0 comments on commit 78c968b

Please sign in to comment.