Skip to content

Instantly share code, notes, and snippets.

http.createServer(dispatchRequest).listen(port);
function dispatchRequest(req, res)
{
res.sentinel = new Sentinel(function (e) {
// Like a catch() clause that catches callbacks too.
// Called if handleRequest throws, or if any of the callbacks
// registered by handleRequest throw, or if any of the
var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
setTimeout(function () {
res.sendHeader(200, {'Content-Type': 'text/plain'});
res.sendBody('Hello World');
res.finish();
}, 2000);
}).listen(3000);
sys.puts('Server running at http://127.0.0.1:3000/');
node helloworld.js
Server running at http://127.0.0.1:3000/
# At this point in another terminal I use netcat to open a plain TCP connection,
# and then Ctrl-C to close the connection without having sent any data.
# node then blows up with:
Segmentation Fault