<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>A blog about server side technologies, nodejs, language design and more.</description><title>TJ Holowaychuk</title><generator>Tumblr (3.0; @tjholowaychuk)</generator><link>http://tjholowaychuk.com/</link><item><title>mad(1) node.js pages</title><description>&lt;p&gt;The node.js markdown documentation is now viewable in the terminal via &lt;a href="http://github.com/visionmedia/mad" target="_blank"&gt;mad(1)&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/1S1u0f0h3i1O252P0G46/Screen%20Shot%202012-05-19%20at%204.59.51%20PM.png" alt="node man page"/&gt;&lt;/p&gt;

&lt;p&gt;Just use &lt;code&gt;mad list&lt;/code&gt; to see which pages are available:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/1Z472H232c263D0a332j/Screen%20Shot%202012-05-19%20at%205.21.39%20PM.png" alt="list of node man pages"/&gt;&lt;/p&gt;

&lt;p&gt;If you already have &lt;code&gt;mad(1)&lt;/code&gt; installed simply run &lt;code&gt;mad --update&lt;/code&gt; to grab these new pages, and view with &lt;code&gt;mad node.http&lt;/code&gt; etc.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/23368504100</link><guid>http://tjholowaychuk.com/post/23368504100</guid><pubDate>Sat, 19 May 2012 13:22:00 -0700</pubDate><category>node</category><category>mad</category></item><item><title>Express 3.x alpha reference docs</title><description>&lt;p&gt;Since I don&amp;#8217;t have the Express 3.x site up yet I thought I would whip up a quick set of markdown docs from the source comments using &lt;a href="http://github.com/visionmedia/dox" target="_blank"&gt;dox&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To view these markdown docs in your terminal install &lt;a href="https://github.com/visionmedia/mad" target="_blank"&gt;mad(1)&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd /tmp &amp;amp;&amp;amp; git clone --depth 1 git@github.com:visionmedia/mad.git &amp;amp;&amp;amp; cd mad &amp;amp;&amp;amp; make install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Update your &lt;a href="https://github.com/visionmedia/mad-pages" target="_blank"&gt;mad-pages&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mad --update
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Profit!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mad express
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/0D2z033A0n2N1T421a2I/Screen%20Shot%202012-04-18%20at%205.44.06%20PM.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HINT&lt;/strong&gt;: Press &amp;#8220;/&amp;#8221;, type and press enter to search. The keys &lt;code&gt;u&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt; move to the prev / next occurrences:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/1C0P0W0L1H241I3p0e2a/Screen%20Shot%202012-04-18%20at%205.28.45%20PM.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HINT HINT&lt;/strong&gt;: There are also &lt;code&gt;mad(1)&lt;/code&gt; pages for Jade, HTTP status codes, errnos and others.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/21354415454</link><guid>http://tjholowaychuk.com/post/21354415454</guid><pubDate>Wed, 18 Apr 2012 17:47:00 -0700</pubDate><category>express</category><category>mad</category></item><item><title>Express 3.0.0 alpha1</title><description>&lt;p&gt;I just released the first alpha, but beware! the documentation has not been updated. I wanted to defer a release until I had time to re-write the site, but meanwhile people have been using the &lt;em&gt;master&lt;/em&gt; branch anyway, so we might as well make it official (and available via npm).&lt;/p&gt;

&lt;p&gt;The alpha is by no means complete, some features still need adjusting, though mainly internal refactoring. The wiki contains both the &lt;a href="https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x" target="_blank"&gt;2.x to 3.x migration&lt;/a&gt; guide, and documentation for most of the &lt;a href="https://github.com/visionmedia/express/wiki/New-features-in-3.x" target="_blank"&gt;new features&lt;/a&gt; added. It&amp;#8217;s worth noting you&amp;#8217;ll also gain new features from Connect 2.x as well, which Express 3.x depends on.&lt;/p&gt;

&lt;p&gt;There are quite a few new http utilities, better reverse proxy support, and refinements to the view system. Express 3.x is even smaller than 2.x totalling 975 SLOC according to &lt;code&gt;sloc(1)&lt;/code&gt;, where Express 2.x was around 1300. Most of the effort goes into actually removing and refining code to increase quality, and &lt;em&gt;lots&lt;/em&gt; of test coverage (4286 SLOC).&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve also started a Express 4.x &lt;a href="https://github.com/visionmedia/express/wiki/4.x-roadmap" target="_blank"&gt;Roadmap&lt;/a&gt; with some details on where things &lt;em&gt;may&lt;/em&gt; go in the future.&lt;/p&gt;

&lt;h2&gt;Contributing&lt;/h2&gt;

&lt;p&gt;If you&amp;#8217;d like to contribute, one of the best ways right now would be to help upgrade the ./examples&amp;#160;! The Express repo has many examples, roughly half of which still use 2.x code and may not work. This time around we have test coverage for these examples, but many still need to be upgraded. To contribute first install the development dependencies:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then run the acceptance tests:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ make test-acceptance
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Add some tests for an example, write some tests, make sure they work, then open a pull-request :)&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s all for now! When I have time I&amp;#8217;ll be rewriting the site, updating the wiki, and of course finishing the release.  If there&amp;#8217;s anything you find yourself doing often and think has a home in core let me know!&lt;/p&gt;

&lt;p&gt;cheers!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; If you&amp;#8217;re looking for docs we now have some auto-generated docs that you can view in your terminal. View this &lt;a href="http://tjholowaychuk.com/post/21354415454/express-3-x-alpha-reference-docs" target="_blank"&gt;post&lt;/a&gt;.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/21162751096</link><guid>http://tjholowaychuk.com/post/21162751096</guid><pubDate>Sun, 15 Apr 2012 12:21:00 -0700</pubDate><category>express</category><category>node</category></item><item><title>Going mad(1)</title><description>&lt;p&gt;&lt;a href="https://github.com/visionmedia/mad" target="_blank"&gt;mad(1)&lt;/a&gt; is a tiny tool that allows you to view markdown manual pages. I&amp;#8217;m a huge fan of &lt;code&gt;man&lt;/code&gt; in general, but the format is pretty annoying and often converted from markdown, textile etc anyway. The output &lt;code&gt;man&lt;/code&gt; produces is also pretty bad in my opinion, mainly whitespace issues.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/2G271F3c0D3p2i2V3l3k/Screen%20Shot%202012-04-14%20at%2012.44.58%20PM.png" alt="markdown man page"/&gt;&lt;/p&gt;

&lt;p&gt;This is just a quick 5 minute hack so follow if you&amp;#8217;re interested or open an issue if you have some ideas! It would be great to allow customization of colors, formatting, blah blah. Here&amp;#8217;s another screenshot:&lt;/p&gt;

&lt;p&gt;&lt;img src="https://a248.e.akamai.net/camo.github.com/f5ed9ecc34159446e36c0f76354d78ff6b52ba7d/687474703a2f2f662e636c2e6c792f6974656d732f33673176325732313353324e33393042323031712f53637265656e25323053686f74253230323031322d30342d31342532306174253230312e35342e3335253230504d2e706e67" alt="jade"/&gt;&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/21100445420</link><guid>http://tjholowaychuk.com/post/21100445420</guid><pubDate>Sat, 14 Apr 2012 12:59:00 -0700</pubDate><category>mad</category><category>bash</category></item><item><title>Mocha 1.0</title><description>&lt;p&gt;The &lt;a href="http://github.com/visionmedia/mocha" target="_blank"&gt;Mocha&lt;/a&gt; JavaScript test framework has hit 1.0 with a bunch of great contributions from the community, here&amp;#8217;s the change log:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Added js API. Closes #265&lt;/li&gt;
&lt;li&gt;Added: initial run of tests with &lt;code&gt;--watch&lt;/code&gt;. Closes #345&lt;/li&gt;
&lt;li&gt;Added: mark &lt;code&gt;location&lt;/code&gt; as a global on the CS. Closes #311&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;markdown&lt;/code&gt; reporter (github flavour)&lt;/li&gt;
&lt;li&gt;Added: scrolling menu to coverage.html. Closes #335&lt;/li&gt;
&lt;li&gt;Added source line to html report for Safari [Tyson Tate]&lt;/li&gt;
&lt;li&gt;Added &amp;#8220;min&amp;#8221; reporter, useful for &lt;code&gt;--watch&lt;/code&gt; [Jakub Nešetřil]&lt;/li&gt;
&lt;li&gt;Added support for arbitrary compilers via . Closes #338 [Ian Young]&lt;/li&gt;
&lt;li&gt;Added Teamcity export to lib/reporters/index [Michael Riley]&lt;/li&gt;
&lt;li&gt;Fixed chopping of first char in error reporting. Closes #334 [reported by topfunky]&lt;/li&gt;
&lt;li&gt;Fixed terrible FF / Opera stack traces&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;Compiler support&lt;/h2&gt;

&lt;p&gt;coffee-script out of the box was &lt;em&gt;removed&lt;/em&gt;, now you can used the &lt;code&gt;--compilers &amp;lt;ext&amp;gt;:&amp;lt;module&amp;gt;,...&lt;/code&gt; flag to map a compiler to the given extension name. For example &lt;code&gt;mocha --compilers coffee:coffee-script&lt;/code&gt;. There are simply too many foo -&amp;gt; JavaScript transpilers to directly support, this pushes that back on the author.&lt;/p&gt;

&lt;h2&gt;Min reporter&lt;/h2&gt;

&lt;p&gt;First up is the &lt;code&gt;min&lt;/code&gt; reporter by Jakub Nešetřil, this tiny reporter works great with &lt;code&gt;--watch&lt;/code&gt;, outputting the summary only, though still reporting verbose errors on failure. &lt;img src="http://f.cl.ly/items/460B2r3p3M3k2D3J250m/Screen%20Shot%202012-03-24%20at%2010.46.01%20AM.png" alt=""/&gt;&lt;/p&gt;

&lt;h2&gt;Markdown reporter&lt;/h2&gt;

&lt;p&gt;I added a &lt;code&gt;markdown&lt;/code&gt; reporter which can be used to display your tests as documentation in a Github wiki page, or simply a markdown file in your repository that you can link to. For example here are the Connect &lt;a href="https://github.com/senchalabs/connect/blob/90a725343c2945aaee637e799b1cd11e065b2bff/tests.md" target="_blank"&gt;markdown test docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not super happy with how much padding Github adds, so the TOC looks pretty messy, but all of these document-style reporting mechanisms make you think twice about how clean and organized your tests are.&lt;/p&gt;

&lt;h2&gt;JavaScript API&lt;/h2&gt;

&lt;p&gt;A new JS API was added, which &lt;code&gt;mocha(1)&lt;/code&gt; now utilizes. This higher-level JS API will make it easier for those who want to script the testing process with Mocha. I have yet to document this API but it looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var Mocha = require('mocha');

var mocha = new Mocha;
mocha.reporter('spec').ui('bdd');

mocha.addFile('test/suite.js');
mocha.addFile('test/runner.js');
mocha.addFile('test/runnable.js');

var runner = mocha.run(function(){
  console.log('finished');
});

runner.on('pass', function(test){
  console.log('... %s passed', test.title);
});

runner.on('fail', function(test){
  console.log('... %s failed', test.title);
});
&lt;/code&gt;&lt;/pre&gt;</description><link>http://tjholowaychuk.com/post/19843730724</link><guid>http://tjholowaychuk.com/post/19843730724</guid><pubDate>Sat, 24 Mar 2012 10:58:00 -0700</pubDate><category>mocha</category><category>nodejs</category><category>javascript</category></item><item><title>amysteen:

Maru being Maru.</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_m1cuu8KVtY1qkt1a7o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;a href="http://amysteen.tumblr.com/post/19795495435/maru-being-maru" class="tumblr_blog" target="_blank"&gt;amysteen&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Maru being Maru.&lt;/p&gt;&lt;/blockquote&gt;</description><link>http://tjholowaychuk.com/post/19842979990</link><guid>http://tjholowaychuk.com/post/19842979990</guid><pubDate>Sat, 24 Mar 2012 10:43:49 -0700</pubDate></item><item><title>Redis Lua scripting is badass</title><description>&lt;p&gt;Roughly a year ago Salvatore Sanfilippo the author of Redis
  wrote a &lt;a href="http://antirez.com/post/redis-and-scripting.html" target="_blank"&gt;blog post&lt;/a&gt;
  discussing the inclusion of &lt;a href="http://www.lua.org/" target="_blank"&gt;Lua&lt;/a&gt; as a scripting language. I
  &lt;em&gt;finally&lt;/em&gt; decided to try this out, and let&amp;#8217;s just say it&amp;#8217;s pretty &lt;em&gt;badass&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Lua is a great fit for Redis, they have similar philosophies, being simple,
  small, and fast. Suppose for example you have 200,000 jobs, each represented
  in Redis as a hash, and you want to map/reduce the job duration, the new scripting
  capabilities make this really easy!&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the node setup script to generate these jobs:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  var redis = require('redis')
    , db = redis.createClient();

  var n = 500000
    , pending = n
    , ms;

  while (n--) {
    ms = Math.random() * 200 | 0;
    db.hset('job:' + n, 'duration', ms, function(){
      --pending || process.exit();
    })
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next here is what you might consider scripting in your host language
  without the new Redis scripting feature, manually reducing the value:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  var redis = require('redis')
    , db = redis.createClient();

  var n = 200000
    , start = new Date
    , pending = n
    , ms = 0;

  while (n--) {
    db.hget('job:' + n, 'duration', function(err, n){
      if (err) throw err;
      ms += ~~n;
      --pending || (function(){
        console.log('%d minutes spent processing jobs', ms / (1000 * 60) | 0);
        console.log('took %ds', (new Date - start) / 1000 | 0);
        process.exit();
      })();
    })
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;On my Air this took roughly 7s, not too great, keep in mind that there is no throttling here I&amp;#8217;m just plastering it with 200k commands. Now let&amp;#8217;s try it with Lua! The
   following script is ad-hoc, but it&amp;#8217;ll do the trick. To signal an error all you
   have to do is return a table with the &lt;code&gt;err&lt;/code&gt; slot. &lt;code&gt;redis.call()&lt;/code&gt; is effectively
   the public Redis API exposed to your Redis script, so you can use it just like you
   would your host language Redis bindings or &lt;code&gt;redis-cli(1)&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   local sum = 0
   for i = 0, 200000, 1 do
     local key = "job:" .. i
     local ms = tonumber(redis.call("hget", key, "duration"))
     if ms == nil then return { err = key .. " is not an integer" } end
     sum = sum + ms
   end
   return sum
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here I&amp;#8217;ve embedded it in the JS script, but you could of course generate these,
   load them from files etc (beware of redis-injection?).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   var redis = require('redis')
     , db = redis.createClient();

   var script = '\
   local sum = 0 \
   for i = 0, 200000, 1 do \
     local key = "job:" .. i \
     local ms = tonumber(redis.call("hget", key, "duration")) \
     if ms == nil then return { err = key .. " is not an integer" } end \
     sum = sum + ms \
   end \
   return sum';

   var start = new Date;

   db.eval(script, 0, function(err, ms){
     if (err) throw err;
     console.log('%d minutes spent processing jobs', ms / (1000 * 60) | 0);
     console.log('took %dms', new Date - start | 0);
     process.exit();
   });
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After running the script with the new &lt;strong&gt;EVAL&lt;/strong&gt; command what previously took
  several seconds dropped to ~850ms, &lt;em&gt;much&lt;/em&gt; better. &lt;strong&gt;EVAL&lt;/strong&gt; and &lt;strong&gt;EVALSHA&lt;/strong&gt;
  are actually a lot more flexible than I&amp;#8217;ve explained here, accepting keys
  and arbitrary arguments.&lt;/p&gt;

&lt;p&gt;Check out &lt;a href="http://antirez.com/post/an-update-on-redis-and-lua.html" target="_blank"&gt;antirez.com/post/an-update-on-redis-and-lua.html&lt;/a&gt; for more.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/19321054250</link><guid>http://tjholowaychuk.com/post/19321054250</guid><pubDate>Wed, 14 Mar 2012 18:23:00 -0700</pubDate><category>redis</category><category>lua</category><category>node</category><category>js</category></item><item><title>Mocha string diffs</title><description>&lt;p&gt;Mocha 0.14.0 adds a single feature - string diffs! This is a small but very handy feature for some. When the strings are small, Mocha will use a character diff, when consisting of several lines a line-numbered &amp;#8220;gutter&amp;#8221; is added and a word diff is used as shown in the following image:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/3L0T1A0h2N1J3G021i0F/Screen%20Shot%202012-03-01%20at%202.31.31%20PM.png" alt="mocha string diff example"/&gt;&lt;/p&gt;

&lt;p&gt;This is very useful when authoring things like template engines, transpilers, and other string-based libraries. For example the &lt;a href="http://github.com/learnboost/stylus" target="_blank"&gt;Stylus&lt;/a&gt; test suite is comprised of nothing but acceptance tests, the input file is compiled, and the resulting CSS is checked using &lt;code&gt;actual.trim().should.equal(css);&lt;/code&gt;. In combination with Mocha&amp;#8217;s BDD interface I can now simply iterate through the files and define test-cases as shown here:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  var stylus = require('../')
    , fs = require('fs');

  // test cases

  var cases = fs.readdirSync('test/cases').filter(function(file){
    return ~file.indexOf('.styl');
  }).map(function(file){
    return file.replace('.styl', '');
  });

  describe('integration', function(){
    cases.forEach(function(test){
      var name = test.replace(/[-.]/g, ' ');
      it(name, function(){
        var path = 'test/cases/' + test + '.styl';
        var styl = fs.readFileSync(path, 'utf8');
        var css = fs.readFileSync('test/cases/' + test + '.css', 'utf8');

        var style = stylus(styl)
          .set('filename', path)
          .include(__dirname + '/images')
          .include(__dirname + '/cases/import.basic')
          .define('url', stylus.url());

        if (~test.indexOf('compress')) style.set('compress', true);

        style.render(function(err, actual){
          if (err) throw err;
          actual.trim().should.equal(css);
        });
      })
    });
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now if something were go to wrong, you get a nice diff!&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/3r42033a031T0W392R1W/Screen%20Shot%202012-03-01%20at%203.25.56%20PM.png" alt="stylus diff example"/&gt;&lt;/p&gt;

&lt;h2&gt;Assertion library authors&lt;/h2&gt;

&lt;p&gt;To support this feature all you have to do is populate &lt;code&gt;err.expected&lt;/code&gt; and &lt;code&gt;err.actual&lt;/code&gt; with their respective values, Mocha will take care of the presentation.&lt;/p&gt;

&lt;p&gt;NOTE: I just toggled the colors, green is now the expected color&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/18574009869</link><guid>http://tjholowaychuk.com/post/18574009869</guid><pubDate>Thu, 01 Mar 2012 15:29:00 -0800</pubDate><category>mocha</category><category>js</category><category>node</category></item><item><title>Connect 2.0</title><description>&lt;p&gt;Connect 2.0 is here with new core middleware, miscellaneous improvements, and some new &lt;a href="http://www.senchalabs.org/connect/" target="_blank"&gt;docs&lt;/a&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var app = connect()
  .use(connect.logger('dev'))
  .use(connect.static('public'))
  .use(function(req, res){
    res.end('hello world\n');
  })

 app.listen(3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;HTTP and HTTPS&lt;/h3&gt;

&lt;p&gt;Previously &lt;code&gt;connect.Server&lt;/code&gt; inherited from Node&amp;#8217;s core &lt;code&gt;net.Server&lt;/code&gt;, this made it difficult to provide both HTTP and HTTPS for your application. The result of &lt;code&gt;connect()&lt;/code&gt; (formerly &lt;code&gt;connect.createServer()&lt;/code&gt;) is now simply a JavaScript &lt;code&gt;Function&lt;/code&gt;. This means that you may omit the call to &lt;code&gt;app.listen()&lt;/code&gt;, and simply pass &lt;code&gt;app&lt;/code&gt; to a Node &lt;code&gt;net.Server&lt;/code&gt; as shown here:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var connect = require('connect')
  , http = require('http')
  , https = require('https');

var app = connect()
  .use(connect.logger('dev'))
  .use(connect.static('public'))
  .use(function(req, res){
    res.end('hello world\n');
  })

http.createServer(app).listen(80);
https.createServer(tlsOptions, app).listen(443);
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Body parsers&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;bodyParser()&lt;/code&gt; middleware is now nothing but a short-hand for adding the &lt;code&gt;json()&lt;/code&gt;, &lt;code&gt;multipart()&lt;/code&gt;, and &lt;code&gt;urlencoded()&lt;/code&gt; middleware. Each of these populate &lt;code&gt;req.body&lt;/code&gt; with an object containing the parsed values, &lt;code&gt;multipart()&lt;/code&gt; provides &lt;code&gt;req.body&lt;/code&gt; and &lt;code&gt;req.files&lt;/code&gt; for uploads.&lt;/p&gt;

&lt;h3&gt;Core compression&lt;/h3&gt;

&lt;p&gt;As of Node 0.6.0 fast, native compression capabilities are available, so now we have the &lt;code&gt;compress()&lt;/code&gt; middleware supporting deflate and gzip.&lt;/p&gt;

&lt;h3&gt;Cookie parser&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;cookieParser()&lt;/code&gt; middleware now supports signed cookies, and accepts a &lt;code&gt;secret&lt;/code&gt;. This replaces the need to pass &lt;code&gt;session({ secret: string })&lt;/code&gt; to the &lt;code&gt;session()&lt;/code&gt; middleware. Signed cookies are available via &lt;code&gt;req.signedCookies&lt;/code&gt;, and unsigned as &lt;code&gt;req.cookies&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Error delegation&lt;/h2&gt;

&lt;p&gt;Previously a few of the core middleware would respond to error situations directly, these have been changed to simply &lt;code&gt;next(err)&lt;/code&gt;-them along. This change allows you to specify customized behaviour by adding an error-handling middleware:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;app.use(function(err, req, res, next){
  if (4 == err.status / 100) {
    // render a client-error page
  } else {
    // render a server-error page
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Session&lt;/h3&gt;

&lt;p&gt;As mentioned &lt;code&gt;session()&lt;/code&gt; no longer requires a &lt;code&gt;secret&lt;/code&gt;. The cookie &lt;code&gt;.maxAge&lt;/code&gt; has been defaulted to &lt;code&gt;null&lt;/code&gt;, meaning that it will be a browser-session cookie, expiring once the visitor closes their browser.&lt;/p&gt;

&lt;h3&gt;Third-party middleware&lt;/h3&gt;

&lt;p&gt;Third-party middleware should remain perfectly functional. This release of Connect is &lt;em&gt;not&lt;/em&gt; compatible with Express 2.x, Express 3.0 is coming soon.&lt;/p&gt;

&lt;h3&gt;Changelog&lt;/h3&gt;

&lt;p&gt;The following significant changes were made, as well as several others that do not impact public API, such as a full rewrite of the tests using &lt;a href="http://visionmedia.github.com/mocha" target="_blank"&gt;Mocha&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Added &lt;code&gt;cookieSession()&lt;/code&gt; middleware for cookie-only sessions&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;compress()&lt;/code&gt; middleware for gzip / deflate support&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;session()&lt;/code&gt; &amp;#8220;proxy&amp;#8221; setting to trust &lt;code&gt;X-Forwarded-Proto&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;json()&lt;/code&gt; middleware to parse &amp;#8220;application/json&amp;#8221;&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;urlencoded()&lt;/code&gt; middleware to parse &amp;#8220;application/x-www-form-urlencoded&amp;#8221;&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;multipart()&lt;/code&gt; middleware to parse &amp;#8220;multipart/form-data&amp;#8221;&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;cookieParser(secret)&lt;/code&gt; support so anything using this middleware may access signed cookies&lt;/li&gt;
&lt;li&gt;Added signed cookie support to &lt;code&gt;cookieParser()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Added support for JSON-serialized cookies to &lt;code&gt;cookieParser()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;err.status&lt;/code&gt; support in Connect&amp;#8217;s default end-point&lt;/li&gt;
&lt;li&gt;Added X-Cache MISS / HIT to &lt;code&gt;staticCache()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Added public &lt;code&gt;res.headerSent&lt;/code&gt; checking nodes &lt;code&gt;res._headerSent&lt;/code&gt; until node does&lt;/li&gt;
&lt;li&gt;Changed &lt;code&gt;basicAuth()&lt;/code&gt; req.remoteUser to req.user&lt;/li&gt;
&lt;li&gt;Changed: default &lt;code&gt;session()&lt;/code&gt; to a browser-session cookie. Closes #475&lt;/li&gt;
&lt;li&gt;Changed: no longer lowercase cookie names&lt;/li&gt;
&lt;li&gt;Changed &lt;code&gt;bodyParser()&lt;/code&gt; to use &lt;code&gt;json()&lt;/code&gt;, &lt;code&gt;urlencoded()&lt;/code&gt;, and &lt;code&gt;multipart()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Changed: &lt;code&gt;errorHandler()&lt;/code&gt; is now a development-only middleware&lt;/li&gt;
&lt;li&gt;Changed middleware to &lt;code&gt;next()&lt;/code&gt; errors when possible so applications can unify logging / handling&lt;/li&gt;
&lt;li&gt;Removed &lt;code&gt;http[s].Server&lt;/code&gt; inheritance, now just a function, making it easy to have an app providing both http and https&lt;/li&gt;
&lt;li&gt;Removed &lt;code&gt;.createServer()&lt;/code&gt; (use &lt;code&gt;connect()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Removed &lt;code&gt;secret&lt;/code&gt; option from &lt;code&gt;session()&lt;/code&gt;, use &lt;code&gt;cookieParser(secret)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Removed &lt;code&gt;connect.session.ignore&lt;/code&gt; array support&lt;/li&gt;
&lt;li&gt;Removed &lt;code&gt;router()&lt;/code&gt; middleware. Closes #262&lt;/li&gt;
&lt;li&gt;Fixed: set-cookie only once for browser-session cookies&lt;/li&gt;
&lt;li&gt;Fixed FQDN support. dont add leading &amp;#8220;/&amp;#8221;&lt;/li&gt;
&lt;li&gt;Fixed 404 XSS attack vector. Closes #473&lt;/li&gt;
&lt;li&gt;Fixed &lt;strong&gt;HEAD&lt;/strong&gt; support for 404s and 500s generated by Connect&amp;#8217;s end-point&lt;/li&gt;
&lt;/ul&gt;</description><link>http://tjholowaychuk.com/post/18418627138</link><guid>http://tjholowaychuk.com/post/18418627138</guid><pubDate>Mon, 27 Feb 2012 19:18:00 -0800</pubDate><category>connect</category><category>nodejs</category></item><item><title>Mocha test coverage</title><description>&lt;p&gt;The latest release of &lt;a href="http://visionmedia.github.com/mocha" target="_blank"&gt;Mocha&lt;/a&gt; adds two new reporters, now totaling 13 packaged with the library. The two new ones are &amp;#8220;json-cov&amp;#8221; and &amp;#8220;html-cov&amp;#8221;, the latter inherits from the former in order to produce a single-page test coverage report.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://f.cl.ly/items/3T3G1h1d3Z2i3M3Y1Y0Y/Screen%20Shot%202012-02-23%20at%208.37.13%20PM.png" target="_blank"&gt;&lt;img src="http://f.cl.ly/items/3T3G1h1d3Z2i3M3Y1Y0Y/Screen%20Shot%202012-02-23%20at%208.37.13%20PM.png" alt="test coverage example"/&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re curious what a live example looks like, check out &lt;a href="http://visionmedia.github.com/mocha/coverage.html" target="_blank"&gt;this page&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Setup&lt;/h3&gt;

&lt;p&gt;With Node&amp;#8217;s &lt;code&gt;require.paths&lt;/code&gt; array out of the picture there&amp;#8217;s a bit of boiler-plate involved in setting up test coverage for your project, but it&amp;#8217;s pretty minimal. First you&amp;#8217;ll want to install the &lt;a href="https://github.com/visionmedia/node-jscoverage" target="_blank"&gt;jscoverage&lt;/a&gt; executable, this program parses your source code and spits out an instrumented version, effectively a bunch of lines that look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  $_jscoverage[filename][line]++;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This enables libraries like Mocha to execute the code as they normally would, however we can then extract this coverage information and generate fancy reports. jscoverage takes the input directory, and an output directory, I usually calls this &amp;#8220;lib-cov&amp;#8221;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; $ jscoverage lib lib-cov
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Typically when testing your library you&amp;#8217;ll use relative &lt;code&gt;require()&lt;/code&gt; calls that look like this: &lt;code&gt;var express = require('../')&lt;/code&gt;, and the library entry point is &lt;code&gt;./index.js&lt;/code&gt;. Normally this file might look something like below, or you may not have an &lt;code&gt;./index.js&lt;/code&gt; file at all.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  module.exports = require('./lib/express');
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;By using &lt;code&gt;./index.js&lt;/code&gt; we can then alter this statement to conditionally export the instrumented version when the &lt;strong&gt;EXPRESS_COV&lt;/strong&gt; environment variable is present:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; module.exports = process.env.EXPRESS_COV
   ? require('./lib-cov/express')
   : require('./lib/express');
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then all you need to do is invoke &lt;code&gt;mocha&lt;/code&gt; with &lt;code&gt;--reporter html-cov&lt;/code&gt; and redirect the stdout to a file such as &lt;em&gt;coverage.html&lt;/em&gt;. Line 25 the &lt;code&gt;test-cov&lt;/code&gt; target of the Express &lt;a href="https://github.com/visionmedia/express/blob/b6ee5fafd0d6c79cf7df5560cb324ebee4fe3a7f/Makefile" target="_blank"&gt;Makefile&lt;/a&gt; illustrates how I typically handle this but depending on your setup it may vary.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s it! remember to add &amp;#8220;coverage.html&amp;#8221; to your &lt;em&gt;.npmignore&lt;/em&gt; and &lt;em&gt;.gitignore&lt;/em&gt; files ;)&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/18175682663</link><guid>http://tjholowaychuk.com/post/18175682663</guid><pubDate>Thu, 23 Feb 2012 21:30:00 -0800</pubDate><category>mocha</category><category>js</category><category>nodejs</category><category>testing</category></item><item><title>Stylus gets @extend</title><description>&lt;p&gt;&lt;strong&gt;@extend&lt;/strong&gt; is a great little feature which originated in &lt;a href="http://sass-lang.com/" target="_blank"&gt;SASS&lt;/a&gt;, and now finds a home in &lt;a href="http://learnboost.github.com/stylus/" target="_blank"&gt;Stylus&lt;/a&gt;. If you&amp;#8217;ve ever written CSS like this, you know it can become quite the pain to maintain large lists of selectors:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.message,
.warning,
.error {
  font-size: 14px;
  padding: 5px 10px;
  border: 1px solid #eee;
  border-radius: 5px;
}

.warning {
  color: yellow;
}

.error {
  color: red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;@extend&lt;/strong&gt; makes this process flow naturally, and even supports inheritance. In Stylus you may use &lt;strong&gt;@extend&lt;/strong&gt; or &lt;strong&gt;@extends&lt;/strong&gt;, I prefer the latter personally but that&amp;#8217;s up to you! Using this feature you would define &lt;code&gt;.message&lt;/code&gt; on it&amp;#8217;s own, and simply __@extend_ it from within the other rulesets:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.message {
  font-size: 14px;
  padding: 5px 10px;
  border: 1px solid #eee;
  border-radius: 5px;
}

.warning {
  @extends .message;
  color: yellow;
}

.error {
  @extends .message;
  color: red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Taking this even further with inheritance:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.fatal-error {
  @extends .error;
  font-weight: bold
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Would yield the following CSS:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.message,
.warning,
.error,
.fatal-error {
  font-size: 14px;
  padding: 5px 10px;
  border: 1px solid #eee;
  border-radius: 5px;
}
.warning {
  color: #ff0;
}
.error,
.fatal-error {
  color: #f00;
}
.fatal-error {
  font-weight: bold;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here&amp;#8217;s another example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;form
  button
    padding: 10px
    border: 1px solid #eee
    border-radius: 5px

ul
  li a
    @extends form button
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Yielding:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;form button,
ul li a {
  padding: 10px;
  border: 1px solid #eee;
  border-radius: 5px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And of course you may utilize the alternative Stylus syntax if you prefer:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.message
  font-size: 14px
  padding: 5px 10px
  border: 1px solid #eee
  border-radius: 5px

.warning
  @extends .message
  color: yellow

.error
  @extends .message
  color: red

.fatal-error
  @extends .error
  font-weight: bold
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Grab &lt;a href="https://github.com/learnboost/stylus" target="_blank"&gt;Stylus&lt;/a&gt; 0.22.4 for these goodies!&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/15686199710</link><guid>http://tjholowaychuk.com/post/15686199710</guid><pubDate>Wed, 11 Jan 2012 13:41:23 -0800</pubDate><category>nodejs</category><category>stylus</category><category>css</category></item><item><title>hahaha awesome</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lx5g9fUw891qdlh1io1_250.gif"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;hahaha awesome&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/15550074782</link><guid>http://tjholowaychuk.com/post/15550074782</guid><pubDate>Sun, 08 Jan 2012 19:53:05 -0800</pubDate></item><item><title>Why Stylus is the most CSS-like high-level stylesheet language</title><description>&lt;a href="http://vimeo.com/33462524"&gt;Why Stylus is the most CSS-like high-level stylesheet language&lt;/a&gt;: &lt;p&gt;This short Vimeo screencast illustrates why Stylus is the most like CSS as a stylesheet “preprocessor”. More on Stylus &lt;a href="http://learnboost.github.com/stylus" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/14070358698</link><guid>http://tjholowaychuk.com/post/14070358698</guid><pubDate>Sun, 11 Dec 2011 09:09:00 -0800</pubDate><category>js</category><category>nodejs</category><category>stylus</category><category>screencast</category></item><item><title>node "debug" module</title><description>&lt;a href="https://github.com/visionmedia/debug"&gt;node "debug" module&lt;/a&gt;</description><link>http://tjholowaychuk.com/post/13486276667</link><guid>http://tjholowaychuk.com/post/13486276667</guid><pubDate>Mon, 28 Nov 2011 19:56:00 -0800</pubDate></item><item><title>Connect 1.8.0 - multipart support</title><description>&lt;p&gt;Connect 1.8.0 is a tiny but substantial release because it adds &lt;em&gt;multipart/form-data&lt;/em&gt; support via Felix Geisendörfer&amp;#8217;s fantastic multipart parser &lt;a href="https://github.com/felixge/node-formidable" target="_blank"&gt;formidable&lt;/a&gt;, it&amp;#8217;s great and chances are you&amp;#8217;re already using it!&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;bodyParser()&lt;/code&gt; middleware now unifies multipart, json, and x-www-form-urlencoded parsing, providing the &lt;code&gt;req.body&lt;/code&gt; object containing the parsed data. For security purposes the files are placed in a separate object, &lt;code&gt;req.files&lt;/code&gt;, however just as accessible. A constant struggle that I&amp;#8217;ve seen in the community is the concept of &amp;#8220;missing&amp;#8221; request &lt;em&gt;data&lt;/em&gt; events so this will
prevent further confusion. The downside to this is that if you wish to report upload progress, or access files and fields &lt;em&gt;as&lt;/em&gt; the request is streamed, you will have to use formidable directly.&lt;/p&gt;

&lt;p&gt;Before this addition your use of formidable might look something like the following (with Express):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  app.post('/someform', function(req, res, next){
    var form = new formidable.IncomingForm;
    form.parse(req, function(err, fields, files){
      if (err) return next(err);
      // do something with files.image etc
    });
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With the new &lt;code&gt;bodyParser()&lt;/code&gt; all you need is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  app.use(express.bodyParser());

  app.post('/some-form', function(req, res){
    // do something with req.files.image
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The middleware takes the same options that are mentioned on formidable&amp;#8217;s GitHub repo page, so you can specify things like size limits, retaining extensions, the upload directory etc.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  app.use(express.bodyParser({
    uploadDir: '/tmp/uploads'
  }));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s it! but I think this will cover well above the 80% use-case and prevent a lot of headaches that people have with the previous the inconsistencies.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/12943975936</link><guid>http://tjholowaychuk.com/post/12943975936</guid><pubDate>Thu, 17 Nov 2011 15:47:00 -0800</pubDate><category>connect</category><category>nodejs</category></item><item><title>Batman vs Pedophile (vigilante justice)</title><description>&lt;a href="http://bit.ly/v5bUgE"&gt;Batman vs Pedophile (vigilante justice)&lt;/a&gt;</description><link>http://tjholowaychuk.com/post/12914168031</link><guid>http://tjholowaychuk.com/post/12914168031</guid><pubDate>Wed, 16 Nov 2011 20:38:56 -0800</pubDate></item><item><title>Jade &amp; Stylus 0.16.0 released</title><description>&lt;h2&gt;Jade 0.16.0&lt;/h2&gt;

&lt;p&gt;This release of Jade adds quite a few new features such block support for &lt;code&gt;include&lt;/code&gt;, and template inheritance!&lt;/p&gt;

&lt;h3&gt;Extended grammar&lt;/h3&gt;

&lt;p&gt;Jade currently allows you to use JavaScript all over the place, rather than restricting a subset, or implement its own grammar. While this is flexible it tends to make templates look less like &amp;#8230; templates! In an effort to make Jade more declarative I&amp;#8217;ve added literal support for &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;unless&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;until&lt;/code&gt;, iteration, assignments and others.&lt;/p&gt;

&lt;p&gt;For example I consider it bad practice to define vars in a template, however if you must, you may have previously done something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  - var items = ['foo', 'bar', 'baz']
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Jade now allows for assignment, where the right-hand operand is still a regular javascript expression:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   items = ['foo', 'bar', 'baz']
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As mentioned &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;unless&lt;/code&gt; and friends are supported, so the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; - if (!(foo &amp;amp;&amp;amp; bar))
   p stuff
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;May now be defined as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  unless foo &amp;amp;&amp;amp; bar
    p stuff
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This rule applies to &lt;code&gt;else[ if]&lt;/code&gt; as well:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  if something
    p foo
  else if somethingElse
    p bar
  else
    p baz
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And finally iteration where &lt;code&gt;each&lt;/code&gt; and &lt;code&gt;for&lt;/code&gt; are interchangeable:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; - items.forEach(function(item){
   li= item
 - }) 

each item in items
  li= item

for item in items
  li= item

each item, i in items
  li #{i}: #{item}

each val, key in obj
  li #{key}: #{val}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Include blocks&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;include&lt;/code&gt; directive now supports blocks, so for example one could have &lt;code&gt;head.jade&lt;/code&gt; defined as the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  head
    script(src='/javascripts/jquery.js')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Allowing you to either include the file as-is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  html
    include head
    body
      h1 Title
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or append to the last block defined, adding additional &lt;code&gt;script&lt;/code&gt; tags:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  html
    include head
      script(src='/javascripts/caustic.js')
      script(src='/javascripts/app.js')
    body
      h1 Title
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Template inheritance&lt;/h3&gt;

&lt;p&gt;Jade now supports template inheritance via the &lt;code&gt;block&lt;/code&gt; and &lt;code&gt;extends&lt;/code&gt; keywords. A block is simply a &amp;#8220;block&amp;#8221; (indented) of Jade that may be replaced within a child template, this process is recursive.&lt;/p&gt;

&lt;p&gt;Jade blocks can provide default content if desired, however optional as shown below by &lt;code&gt;block scripts&lt;/code&gt;, &lt;code&gt;block content&lt;/code&gt;, and &lt;code&gt;block foot&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// layout.jade
html
  head
    h1 My Site - #{title}
    block scripts
      script(src='/jquery.js')
  body
    block content
    block foot
      #footer
        p some footer content
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now to extend the layout, simply create a new file and use the &lt;code&gt;extends&lt;/code&gt; directive as shown below, giving the path (with or without the .jade extension). You may now define one or more blocks that will override the parent block content, note that here the &lt;code&gt;foot&lt;/code&gt; block is &lt;em&gt;not&lt;/em&gt; redefined and will output &amp;#8220;some footer content&amp;#8221;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// index.jade
extends layout

block scripts
  script(src='/jquery.js')
  script(src='/pets.js')

block content
  h1= title
  each pet in pets
    include pet
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It&amp;#8217;s also possible to override a block to provide additional blocks, as shown in the following example where &lt;code&gt;content&lt;/code&gt; now exposes a &lt;code&gt;sidebar&lt;/code&gt; and &lt;code&gt;primary&lt;/code&gt; block for overriding, or the child template could override &lt;code&gt;content&lt;/code&gt; all together.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// funky-layout.jade
extends layout

block content
  .sidebar
    block sidebar
      p nothing
  .primary
    block primary
      p nothing
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For the rest of the changes and bug fixes check out the &lt;a href="https://github.com/visionmedia/jade/blob/master/History.md" target="_blank"&gt;changelog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Stylus 0.16.0&lt;/h2&gt;

&lt;p&gt;Fewer changes than the latest Jade however still some good ones!&lt;/p&gt;

&lt;h2&gt;:= operator&lt;/h2&gt;

&lt;p&gt;This new operator is an alias of &lt;code&gt;?=&lt;/code&gt; operator, because I think &lt;code&gt;?=&lt;/code&gt; is difficult to read in large quantities for configuration etc:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;grid-columns ?= 16
grid-column-width ?= 40px
grid-gutter-width ?= 20px
extra-space ?= 40px

grid-columns := 16
grid-column-width := 40px
grid-gutter-width := 20px
extra-space := 40px
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Adjusting color lightness&lt;/h2&gt;

&lt;p&gt;While the &lt;code&gt;lighten(color, amount)&lt;/code&gt; and &lt;code&gt;darken(color, amount)&lt;/code&gt; BIFs are still available, the &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt; operators now provide the same functionality when used with percentages as illustrated below:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  lighten(black, 50%)
  // =&amp;gt; #808080

  black + 50%
  // =&amp;gt; #808080
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;fade-in() &amp;amp; fade-out() BIFs&lt;/h2&gt;

&lt;p&gt;These small built-in functions are defined in stylus as the following to adjust the opacity:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  // decerase opacity by amount

  fade-out(color, amount)
    color - rgba(black, amount)

  // increase opacity by amount

  fade-in(color, amount)
    color + rgba(black, amount)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;fade-out(#eee, .5)
// =&amp;gt; rgba(238,238,238,0.50);

fade-out(fade-out(#eee, .3), .5)
// =&amp;gt; rgba(238,238,238,0.20);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Check out the &lt;a href="https://github.com/learnboost/stylus/blob/master/History.md" target="_blank"&gt;changelog&lt;/a&gt; for the other bugfixes and additions.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/10695801204</link><guid>http://tjholowaychuk.com/post/10695801204</guid><pubDate>Mon, 26 Sep 2011 12:56:00 -0700</pubDate></item><item><title>Stylus 0.15.1 - new property reference &amp; @keyframes fabrication features</title><description>&lt;p&gt;Stylus 0.15.x adds a bunch of cool new functionality as well as some important bug fixes.&lt;/p&gt;

&lt;h2&gt;@keyframes fabrication&lt;/h2&gt;

&lt;p&gt;The new keyframes fabrication support automatically duplicates your &lt;strong&gt;@keyframes&lt;/strong&gt; definitions to support vendor prefixes. Note that this is &lt;em&gt;only&lt;/em&gt; a default, as shown below:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@-moz-keyframes foo {
  0% {
    color: #000;
  }

  100% {
    color: #fff;
  }
}
@-webkit-keyframes foo {
  0% {
    color: #000;
  }

  100% {
    color: #fff;
  }
}
@keyframes foo {
  0% {
    color: #000;
  }

  100% {
    color: #fff;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;one can tweak this functionality using the &lt;code&gt;vendors&lt;/code&gt; list as shown in the following snippet which will only expand to the &lt;code&gt;-webkit-&lt;/code&gt; vendor prefix.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;vendors = moz official

@keyframes foo {
  from {
    color: black
  }
  to {
    color: white
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;vendors&lt;/code&gt; property may be utilized more in the future, and perhaps in frameworks like &amp;#8220;nib&amp;#8221; to unify configuration.&lt;/p&gt;

&lt;h2&gt;Property reference&lt;/h2&gt;

&lt;p&gt;The syntax &lt;code&gt;@&amp;lt;property&amp;gt;&lt;/code&gt; has been introduced to reference values of existing properties. For example if you want to re-use values, you may typically do something like below instead of typing the value several times, also allowing you to use functions with &lt;code&gt;w&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.button
  width: w = 50px
  height: w
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The new property reference syntax allows you to treat properties as variables, which can also be accessed within mixins:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.button
  width: 50px
  height: @width
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Comment compilation&lt;/h2&gt;

&lt;p&gt;When the &lt;code&gt;compress&lt;/code&gt; option is &lt;code&gt;true&lt;/code&gt; Stylus will &lt;em&gt;not&lt;/em&gt; output single-line nor multi-line comments, which are commonly found used for licensing in stylesheet frameworks etc, so it&amp;#8217;s useful to strip these out &lt;em&gt;however&lt;/em&gt; you can now force output with the &lt;code&gt;!&lt;/code&gt; character &lt;code&gt;/*!&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;New built-in functions&lt;/h2&gt;

&lt;p&gt;The math functions &lt;code&gt;cos()&lt;/code&gt; and &lt;code&gt;sin()&lt;/code&gt; were added, as well as exposing &lt;code&gt;PI&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Bug fixes&lt;/h2&gt;

&lt;ul&gt;&lt;li&gt;Fixed @import on windows&lt;/li&gt;
&lt;/ul&gt;</description><link>http://tjholowaychuk.com/post/9686647689</link><guid>http://tjholowaychuk.com/post/9686647689</guid><pubDate>Thu, 01 Sep 2011 17:35:08 -0700</pubDate><category>stylus</category><category>nodejs</category><category>js</category></item><item><title>Connect 1.7.0 - fast static file memory cache and more</title><description>&lt;p&gt;Be sure to update &lt;a href="https://github.com/senchalabs/connect" target="_blank"&gt;Connect&lt;/a&gt; to the latest release 1.7.0 for the following goodies!&lt;/p&gt;

&lt;h2&gt;staticCache() middleware&lt;/h2&gt;

&lt;p&gt;1.7.0 now provides a new middleware named &lt;code&gt;staticCache()&lt;/code&gt;, acting as a memory cache on top of the regular &lt;code&gt;static()&lt;/code&gt; middleware. Older versions of Connect used to provide memory caching, however it was baked right into &lt;code&gt;static()&lt;/code&gt;, bloating the middleware more than necessary.&lt;/p&gt;

&lt;h3&gt;Benchmarks&lt;/h3&gt;

&lt;p&gt;The test file for these benchmarks is a small 4kb readme:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ du -h Readme.md 
4.0K    Readme.md
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and the following ApacheBench command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ ab -n 5000 -c 50 -k http://local/Readme.md
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;First up we have Connect &lt;code&gt;static()&lt;/code&gt;, which does not perform any caching, performing disk I/O each request, serving ~2400rps.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;connect()
  .use(connect.static(__dirname))
  .listen(3000)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next up we have &lt;a href="https://github.com/cloudhead/node-static" target="_blank"&gt;node-static&lt;/a&gt; one of the other popular node solutions, serving ~3800rps&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var static = require('node-static')
  , file = new static.Server(__dirname);

http.createServer(function(req, res){
  file.serve(req, res);
}).listen(3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then we have the new &lt;code&gt;staticCache()&lt;/code&gt; middleware paired with &lt;code&gt;static()&lt;/code&gt; serving ~5000rps, a 24% increase over node-static (which also performs memory caching), and ~52% over &lt;code&gt;static()&lt;/code&gt; alone.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;connect()
  .use(connect.staticCache())
  .use(connect.static(__dirname))
  .listen(3000)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;staticCache()&lt;/code&gt; is configurable, allowing you to specify the maximum number of cache objects to store, and the maximum size allowed, so you can cap resources appropriately. The middleware implements a Least Recently Used algorithm to prioritize popular files, knocking less popular objects out of the cache.&lt;/p&gt;

&lt;h2&gt;res.headerSent&lt;/h2&gt;

&lt;p&gt;Node core has a private flag named &lt;code&gt;res._headerSent&lt;/code&gt;, allowing you to check if the header has been written or not, this is extremely useful in some cases, so Connect has publicized this property as &lt;code&gt;res.headerSent&lt;/code&gt; until Node core does (if ever), using a getter to reference the private property.&lt;/p&gt;

&lt;h2&gt;logger() immediate option&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;logger()&lt;/code&gt; middleware now provides &lt;code&gt;{ immediate: true }&lt;/code&gt;, as by default this middleware will log the &lt;em&gt;response&lt;/em&gt; of a request, not when the request is first received, allowing logging of response-times etc.&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/9682643240</link><guid>http://tjholowaychuk.com/post/9682643240</guid><pubDate>Thu, 01 Sep 2011 16:02:00 -0700</pubDate><category>connect</category><category>nodejs</category></item><item><title>Game prototyping with JavaScript &amp; CSS3</title><description>&lt;p&gt;I wanted to share a quick few-hour &lt;a href="https://github.com/visionmedia/game-prototypes" target="_blank"&gt;game prototype&lt;/a&gt; to hopefully inspire a few people! The industry let-alone browser-based games seem very lacking in imagination and storytelling, or maybe I&amp;#8217;m just not looking hard enough ;) but I miss games like &lt;a href="http://en.wikipedia.org/wiki/Grim_Fandango" target="_blank"&gt;Grim Fandango&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below is a screenshot of the demo, consisting of several DOM nodes to represent parts of the main character, the birds, and the scene. Most of the animation is performed with CSS transitions / animations, some of which are dynamic and use the &lt;a href="https://github.com/visionmedia/move.js" target="_blank"&gt;move.js&lt;/a&gt; library.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/3x09401g2a1i3l3a2V2Y/Screenshot.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;I have yet to profile anything but it runs quite smooth on my machine, and there are many aspects that could be optimized, and some simple ones like ditching jQuery.&lt;/p&gt;

&lt;h2&gt;iPhone gaming&lt;/h2&gt;

&lt;p&gt;Back to the original plan, roughly two years ago before the Ipad came out, I was writing an Objective-C iPhone game with &lt;a href="http://www.cocos2d-iphone.org/" target="_blank"&gt;Cocos2d&lt;/a&gt; and &lt;a href="http://code.google.com/p/chipmunk-physics/" target="_blank"&gt;Chipmunk physics&lt;/a&gt;, two really wicked libraries. The iPhone seemed too small, and at the time the resolution was not great either, not to mention the image size restraints that Apple enforced, so I gave up after a few prototypes, and one full-screen PC prototype.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/2K0j2x2A2a3H2z3c1d0B/Screenshot.png" alt=""/&gt;&lt;/p&gt;

&lt;h2&gt;Browser gaming&lt;/h2&gt;

&lt;p&gt;With the advent of modern browsers, browser gaming is already a lot less shitty than a year or two ago, and it&amp;#8217;s only about to get much better with all the work browser vendors are putting into making sure canvas and friends run smooth as butter.&lt;/p&gt;

&lt;p&gt;The first prototype I wrote was written entirely with Canvas. One of the main benefits of this is a certain level of control that you obtain, it&amp;#8217;s extremely easy to implement features like pausing, to apply post-processing, or ad-hoc features that are difficult with the DOM.&lt;/p&gt;

&lt;p&gt;At first I was pretty happy with the result, until I wrote the prototype using CSS3 and HTML, the performance impact was pretty significant (though I had not implemented dirty rects etc). Certain aspects of gaming are significantly easier using the DOM, for example leveraging z-index and CSS transitions, however contrasting canvas pausing and post-processing are more of a problem. At least with the currently state of browser technologies, it&amp;#8217;s a good idea to mix and match. You can build a large portion of your game using the DOM, and canvas for aspects like particle emitters, or perhaps even WebGL shaders like this &lt;a href="http://hakim.se/experiments/webgl/particles/01/" target="_blank"&gt;awesome demo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Demo&lt;/h2&gt;

&lt;p&gt;The video below shows off some of the interactivity, as well as the tiny scene building tool.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.screenr.com/ZfMs" target="_blank"&gt;&lt;img src="http://f.cl.ly/items/2z0f0l1x2v3b212Z3N1I/Screenshot.png" alt=""/&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The demo consists of ~200 lines of js and ~200 lines of CSS, using CSS for transformations, animations and obviously for styling, while the js performs some basic interactions like the eye-ball targeting, and randomized cat walk routine. The demo also has a small toolkit for 
creating scenes, but it&amp;#8217;s certainly nothing robust.&lt;/p&gt;

&lt;h2&gt;Source&lt;/h2&gt;

&lt;p&gt;You can grab the source on &lt;a href="https://github.com/visionmedia/game-prototypes" target="_blank"&gt;Github&lt;/a&gt;. Ping me of you come up with some cool prototypes!&lt;/p&gt;

&lt;h2&gt;Concepts&lt;/h2&gt;

&lt;p&gt;Some more concepts:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/2b0x162O2i1w140O0U2K/Screenshot.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/2P0F1i2a0R2u3S2j1V1U/Screenshot.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/3G1X1H1f3J00421H1Z2M/Screenshot.png" alt=""/&gt;&lt;/p&gt;</description><link>http://tjholowaychuk.com/post/9524129814</link><guid>http://tjholowaychuk.com/post/9524129814</guid><pubDate>Sun, 28 Aug 2011 17:13:00 -0700</pubDate><category>game</category><category>css</category><category>js</category></item></channel></rss>

