Some experiments performed on Node.js. Because programming is an experimental science.
JavaScript Shell
Permalink
Failed to load latest commit information.
releases
streams
LICENSE.md
README.md
Streams.md

README.md

node-experiments

https://github.com/rsp/node-experiments

Some experiments performed on Node.js. Because programming is an experimental science.

Observations

Stream events

On Node v0.10.31 the behavior of stdin stream events seem strange in that sometimes the 'ready' event gets fired immediately before the end of input (but not always). Also it is not consistent with different types of input (e.g. cat file | program is not consistent with program < file - but not when file is something like /dev/fd/63 in which case it is consistent with the pipe). When you listen only for certain events but not all then it gets even more complicated and in some cases no input can give you more events than some input. See below.

Prerequisites

Some experiments are only shell scripts and don't run any Node code. Some are Node programs.

It should work on any standard Linux/Unix distribution. If it doesn't, please sumbit an issue.

It was written and tested on Ubuntu 14.04 with various versions of Node.

Streams

Experiments with Node.js streams.

See: Streams.md for details.

stdin-events-all.js

Shows what events are fired for the stdin stream with a 'data' event handler.

Interesting examples:

$ ./stdin-events-all.js < /dev/null
$ cat /dev/null | ./stdin-events-all.js
$ ./stdin-events-all.js < <(cat /dev/null)

See: Streams.md for more examples with output.

stdin-events-nodata.js

Shows what events are fired for the stdin stream without a 'data' event handler.

Interesting examples:

$ ./stdin-events-nodata.js
$ cat | ./stdin-events-nodata.js
$ ./stdin-events-nodata.js < /dev/null
$ cat /dev/null | ./stdin-events-nodata.js
$ echo | ./stdin-events-nodata.js

See: Streams.md for more examples with output.

file-events-all.js

Shows what events are fired for the file stream with a 'data' event handler.

Interesting examples:

$ ./file-events-all.js <(cat empty-file)
$ ./file-events-all.js <(cat one-newline)

$ ./file-events-all.js empty-file
$ ./file-events-all.js one-newline

$ ./file-events-all.js .
$ ./file-events-all.js -

file-events-nodata.js

Shows what events are fired for the file stream without a 'data' event handler.

Interesting examples:

$ ./file-events-nodata.js <(cat empty-file)
$ ./file-events-nodata.js <(cat one-newline)

$ ./file-events-nodata.js <(cat /dev/null)
$ ./file-events-nodata.js <(echo)

$ ./file-events-nodata.js empty-file
$ ./file-events-nodata.js one-newline

$ ./file-events-nodata.js .
$ ./file-events-nodata.js -

Releases

Experiments on Node.js releases.

dist-versions

Usage: ./dist-versions

Prints the versions of Node that have their own directory (not just single tarballs). (It will be needed later.)

Author

Rafał Pocztarski - https://github.com/rsp

License

MIT License (Expat). See LICENSE.md for details.