TJ Holowaychuk

Month

July 2010

4 posts

nDistro - Node distribution toolkit

nDistro is a small bash project that allows you to define, and install node distributions within seconds. This means no GIT dependency, no compiling node from source with Make, no need to install node then install npm (node’s package manager).

nDistro distributions are easy to create, share, and install. Before we get into the details lets install nDistro:

$ cd /usr/local/bin && curl http://github.com/visionmedia/ndistro/raw/master/install | sh
Creating a Node Distribution

Pre-installed distributions take the shape of a single dotfile named .ndistro, which is actually a bash script loaded by ndistro. Here is an example of one of mine:

    node 0.1.102
    module senchalabs connect
    module visionmedia express 1.0.0beta2
    module visionmedia connect-form
    module visionmedia connect-redis
    module fictorial redis-node-client
    module visionmedia jade
    module visionmedia ejs

We specify the pre-compiled node binary version, as well as several modules defined by:

 module <username> <project> [version]

Currently the node binaries are fetched from my “nodes” repo, so feel free to contribute some nodes :D

Installing a Distribution

Installing a distro is even easier! In the directory containing .ndistro execute:

$ ndistro

You should see the following stdout (or similar):

$ ndistro

... installing connect
... installing express
... installing connect-form
... installing connect-redis
... installing redis-node-client
... installing jade
... installing ejs
... installing node 0.1.102
... installation complete

BAM!! you now have bin/node, and bin/express to get started creating some cool web apps. Try it out:

$ ./bin/node

node> require('express')
{ version: '1.0.0beta2'
, Server: { [Function] super_: { [Function] super_: [Object] } }
, createServer: [Function]
}
Updating A Distribution

Updating is easy too, want to re-install a module?:

$ rm -fr modules/connect-redis

and then run nDistro again:

$ ndistro

You should see something like:

... already installed connect
... already installed express
... already installed connect-form
... installing connect-redis
################################################ 100.0%
... already installed jade
... already installed ejs
... already installed redis-node-client
... already installed node-formidable
... already created application
... already installed node
... installation complete
Future Ideas
  • Utilize Gists (or create a quick site) to share distro recipes.
  • Utilize wget / curl depending on which is available
  • Expand the API, perhaps allow app skeletons
Jul 26, 201047 notes
#nodejs #ndistro
Express 1.0beta

Yesterday I released Express 1.0.0beta, a Sinatra inspired Node web development framework.

The beta is a near re-write consisting of roughly 300 commits, introducing new features, removing legacy code, and improving documentation. Express now runs on the Connect middleware framework, which replaces the previous concept of a Plugin. The performance of express has also been optimized and can now respond much faster than previous versions.

Connect

By abstracting the Express Plugin’s to a specific middleware framework, the community can now build on, and utilize this functionality to power their own frameworks. Connect currently provides:

  • bodyDecoder Buffers and parses json and urlencoded request bodies (extenable)
  • conditionalGet Provides 304
  • errorHandler Handles exceptions thrown, or passed through the stack
  • debug Outputs debugging console to all html responses
  • format Handles url path extensions or
  • gzip Compresses response bodies with gzip executable
  • lint Aids in middleware development
  • logger Provides common logger support, and custom log formats
  • methodOverride Provides faux HTTP method support via the _method param
  • responseTime Responds with the X-Response-Time header in milliseconds
  • compiler Supports arbitrary static compilation of files, currently supports less and sass.
  • cacheManifest Provides cache manifest for offline apps
  • jsonrpc Provides JSON-RPC 2.0 support
  • staticProvider Serves static files
  • cookieDecoder Provides cookie parsing support
  • session Provides session support
  • cache Provides memory caching
  • pubsub Publish subscribe messaging support
  • repl Read Evaluate Print Loop attached to
  • vhost Virtual host support
Performance Enhancements

Express is now much faster, with a concurrency of 80, and 8000 it can easily serve the typical “Hello World” response with ~10,000 requests per second on my machine. Ruby’s Thin (1.2.7) by comparison serves ~6500 rps. Finally by adding Sinatra in the mix I get ~1900 rps.

These numbers are to be taken lightly of course, and are simply relative, to re-cap:

Express        ~10,000
Rack/Thin      ~6,500
Rack/Sinatra   ~1,900

Graph for fun:

Documentation Overhaul

The new docs include a 1.x Migration Guide which should cover most of the changes that would be required to get you up and running. Another thing worth mentioning is that the docs are now generated via Markdown, and are located within ./docs which provides an easy way for developers to contribute docs.

I also have a Contrib Guide for those who are interested in helping Express out, and of course a completely revamped developers Guide.

For those who like to dig in deep and check out internals, my dox project generates the annotated source for Express.

Application Generating Executable

Express now ships with the express executable, creating app skeletons with a single tiny command:

$ express

thats it! of course view —help for more information.

Future of Express

From now on Express is clutter-free, no more dependencies on random extension libraries, no more high level http client library, just simply performance, routing, responding, configuration, and views. Feel free to post an issue if you find a bug, or have suggestions for focused features that you would like to see in the framework.

Looking forward to 1.0, Happy Express-ing everyone :)

Jul 16, 201039 notes
#express #nodejs
Node JavaScript Test Coverage

Today I released Expresso 0.4.0, a TDD framework for node which uses my node-jscoverage project to instrument your library, providing optional test coverage reporting when the —cov flag is used.

Expresso

If you dont know anything about expresso, it executes tests in parallel, so even ~1000 assertions against live http servers can execute in less than a second. By doing so we unfortunately suffer slightly in terms of reporting, although expresso is entirely CI friendly, and reports both sync, async, and uncaught exceptions in a clean manor.

Coverage Reporting

Below is a test coverage example, currently I report the following:

  • LOC: lines of code
  • SLOC: source lines of code (aka no comments etc)
  • source reports, showing the line numbers as well as coverage hits

More Information

Into writing tests for your node JavaScript? prefer insanely fast execution of async TDD? check out expresso! now! do it! before I go drink

Jul 9, 20109 notes
#nodejs #expresso #tdd #coverage #node-jscoverage
Jade - Haml killer for nodejs

Last night I open sourced my latest project Jade, a template engine for node, focusing on readability, error handling and performance. Jade spawned from several needs, first I was tired of debugging poor JavaScript template implementations, or finding work-arounds for common issues, secondly I love haml’s syntax, however I feel it could be revamped to provide a more enjoyable experience, and lastly … I like parsers!

Examples

So what does this so called “Jade” look like? like this:

!!! 5
html(lang="en")
  head
    title= pageTitle
    :javascript
      | if (foo) {
      |    bar()
      | }
  body
    h1 Jade - node template engine
    #container
      - if (youAreUsingJade)
        p You are amazing
      - else
        p Get on it!

If you are at all familiar with Haml you will see tons of similarities, however with a few important changes. First of all inverting the responsibility of whitespace we can remove the % tag prefix, leading words are now simply tags, and text blocks now contain a margin as indicated by the pipe |. I am sure people will have varying opinions on this, but I find it much easier to read, and more enjoyable to type since your main focus is building a layout, not writing text blocks.

Features

Below are some of the highlights of 0.0.1:

  • high performance parser
  • great readability
  • code is escaped by default for security
  • contextual error reporting at compile & run time
  • executable for compiling jade templates via the command line
  • html 5 mode (using the !!! 5 doctype)
  • optional memory caching
  • combine dynamic and static tag classes
  • no tag prefix
  • filters
    • :sass
    • :markdown
    • :cdata
    • :javascript
Implementations

As of this moment JavaScript (node specifically) is the only Jade implementation, however as with Haml this could easily be ported to other host languages, and I encourage it greatly! Even if you are not a JavaScript guy feel free to try it out, and implement it in your language of choice :)

More Information

Head over to the Github repo, or visit the Jade site for additional examples, installation guides and more.

Jul 1, 201022 notes
#nodejs #jade #haml
Next page →
2012 2013
  • January
  • February 3
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2011 2012 2013
  • January 2
  • February 2
  • March 4
  • April 3
  • May 2
  • June 2
  • July 4
  • August 3
  • September 1
  • October 2
  • November 1
  • December 5
2010 2011 2012
  • January
  • February 3
  • March
  • April 4
  • May 2
  • June 1
  • July 3
  • August 3
  • September 3
  • October
  • November 3
  • December 1
2010 2011
  • January
  • February
  • March
  • April 8
  • May 1
  • June 3
  • July 4
  • August 4
  • September 3
  • October
  • November 1
  • December 1