Tom Hughes-Croucher is going to tell us about Node.js, a JavaScript web server. He starts by offering a doughnut to anyone asking non-awful questions.
Why server-side JavaScript? Well, first there are a lot of JavaScript programmers. Pretty much all web programmers use it, because that’s all they have available on the client. So why not use it on the server, too? And why write things twice, separately for the server and client sides? And progressive enhancement is free (close enough to free).
JavaScript runtimes include V8 (Google) in C++, Spider Monkey (Mozilla) in C++, Rhino (Mozilla) in Java, JavaScript Core (Apple) in C++. V8 is significantly faster than Spider Monkey (at the moment), but Mozilla is coming back with Trace Monkey. Google’s success with V8 has sparked a speed war among JavaScript and browser builders.
Node.js is a server-side JavaScript process that uses V8. It runs on anything POSIX-enough. (May be okay on Cygwin on Windows.) It’s non-blocking and event driven. It uses the CommonJS module format (we’ll find out soon what that means). Node is very fast. It’s almost as fast as nginx, which is all native C and highly optimized.
Here’s some code (I think I got it down right):
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello, World\n'); }).listen(8124, '127.0.0.1'); console.log('Server started.\n');
There are plenty of packages available for Node.js, which can be installed with NPM, the Node Package Manager. Which is itself written in JavaScript.
He shows more examples, and explains how to use things. A very good session.