The JavaScript blog.


grunt build

Build Configuration with Angus

Posted on .


Build tools are great, but they're usually optimised for working on single projects. If you're a freelancer or work for an agency, then you probably work on multiple projects for several clients each day. Angus (GitHub: nickjanssen / angus, License: MIT) by Nick Janssen aims to help improve exactly that type of workflow by sharing a build configuration across all of your applications.

Angus solves these problems by turning the build process into something generic and reusable. It allows you to specify libraries on a per-app basis, while still sharing the same build steps.

Inside Angus, every app is simply a directory inside the apps/a folder with its own repository. The apps/ folder gets ignored by the Angus repository. Each app you make with Angus shares the same globalGruntfile`, but can define all the libraries they need on a per-app level.

Each application can still have its own dependencies. Bower is used for client-side dependencies, but rather than using bower.json files Angus invokes Bower with the necessary package names and version strings.

Nick posted an article to David Walsh's blog about Angus: Building Web Apps Faster Using Angus. It details the installation and configuration process and also shows how to use Angus with Git.


node modules npm git grunt

Node Roundup: husky, grunt-npmcopy

Posted on .


husky (GitHub: typicode / husky, License: MIT, npm: husky) by typicode is a module for helping to avoid bad commits being pushed using Git hooks.

It basically sets up Git hooks for your Node projects:

So what makes husky different?

First, other modules often replace or delete existing hooks. husky won't ever replace or modify an existing hook, so it's a safer choice for a team or an open source project. In other terms, people who have set up their own hooks won't be impacted by husky.

I think also that husky is more easier and straightforward to use compared to others. husky's README is just a few lines and setting up hooks should be simple.

And last, usually other modules introduces unconventional package.json fields, husky uses only valid package.json fields.


grunt-npmcopy (GitHub: timmywil / grunt-npmcopy, License: MIT, npm: grunt-npmcopy) by Timmy Willison allows you to use the same package manager for Node and client-side projects. It helps place client-side dependencies in the right directory by using a Grunt task called npmcopy.

The npmcopy task takes source and destination options so you can avoid copying lots of extra files into your publicly accessible asset directories.

Have you ever wondered why we have so many package managers? NPM, Bower, Component. Why don’t we just pick one? Well, after much deliberation with developers like you, I’ve decided to support the idea that NPM might just be able to handle it all.


node modules images grunt build bower

Gulp, bLazy, grunt-bowercopy

Posted on .



Last night I was reading a post about Gulp by Martin Genev. Martin traces the appearance of Gulp into the JavaScript community, through GitHub comments and Tweets.

Apparently Gulp is a new build system made by Fractal, a Node consultancy with several popular Node modules under their collective belts.

Gulp is built around streams, so it feels more like idiomatic Node. You can pipe files through processors, so if you had a set of LESS files you could convert them into CSS with something like gulp.src('less/*.less').pipe(less()).pipe(minify()).pipe(gulp.dest('styles/screen.css')). It supports tasks as a unit of work, and tasks can have names and dependencies.

The project has 13 contributors already -- most of the work is by Eric Schoffstall who you'll see all over Fractal's other projects. It has tests written with Mocha, and some decent documentation already.


bLazy (GitHub: dinbror / blazy) by Bjoern Klinggaard is a lazy loading image script. It doesn't have any dependencies, and supports callbacks for loading failures:

var bLazy = new Blazy({  
  success: function(ele) {
  error: function(ele, msg) {
    if (msg === 'missing') {
      // Data-src is missing
    } else if (msg === 'invalid') {
      // Data-src is invalid

There's a blog post about bLazy that documents the full API.


I seem to waste a lot of time detangling Bower dependencies to make my client-side builds more efficient. Timmy Willison may have solved this with grunt-bowercopy (GitHub: timmywil / grunt-bowercopy, License: MIT). It allows you to specify where dependencies should go, and can reduce the amount of duplication when creating builds.

It looks like it works the way I expect Bower dependency management to work in Grunt, so I'm going to go back and look at my Grunt/Bower projects to see if I can clean then up with this.


node modules express amazon grunt foundationdb

Node Roundup: Fowl, grunt-ec2, connect-body-rewrite

Posted on .


Fowl (GitHub: OptimalBits / fowl, License: MIT, npm: fowl) by Manuel Astudillo is a document and query layer for FoundationDB. It provides a similar API to NoSQL databases like MongoDB, but has support for multidocument transactions:

Transaction support is an incredibly powerful feature that simplifies server logic and helps avoiding difficult to solve race conditions.

Fowl provides a low level API based on keypaths for describing documents and its properties following CRUD semantics.

It includes tests and each API method is documented in the readme file. Basic usage looks like this:

// Open a foundationDB database

// Create a document (if _id not specify a GUID will be generated)
var john = fowl.create('people', {  
  _id: 'john',
  name: 'John',
  lastname: 'Smith',
  balance: 100

// Use transactions to transfer money from one account to another
var tr = fowl.transaction()

tr.get(['people', 'john', 'balance']).then(function(johnBalance) {  
  tr.put(['people', 'john', 'balance'], johnBalance - 10);


grunt-ec2 (GitHub: bevacqua / grunt-ec2, License: MIT, npm: grunt-ec2) by Nicolas Bevacqua is a set of Grunt tasks for creating, terminating, and deploying Node applications to AWS EC2 instances.

The deployed Node applications are served from behind an Nginx proxy. The task reference explains what each task does -- there are quite a few.

It supports most of the things you want to do when setting up Node applications, including SSL, SSH keys for each instance, rsync support for fast and painless uploads, and hot code swaps.


There are times when the logic of my Node web applications have seemed to need the response body to be rewritten, but in the middleware rather than the main route logic. The connect-body-rewrite (GitHub: rubenv / connect-body-rewrite, License: MIT, npm: connect-body-rewrite) by Ruben Vermeersch makes this possible. The examples use regular expressions to replace text, based on the request headers:

  accept: function (res) {
    return res.getHeader('content-type').match(/text\/html/);
  rewrite: function (body) {
    return body.replace(/<\/body>/, "Copyright 2013 </body>");

I like the way it's designed to use an accept callback, because it makes it easy to see what the rewriter actually does by keeping the logic close together.


frameworks node modules async grunt ES6 typescript

Ground, Generators and Async Patterns in Node, Time Grunt

Posted on .


Ground (GitHub: OptimalBits / ground, License: MIT) from OptimalBits is a web framework for Node that is written with TypeScript:

In ground, most of the application logic is moved from the server to the client, whereas the server acts mostly as an scalable, efficient distributed storage and synchronization controller.

It includes also some rather useful features such as a hierarchical routing system, an undo/redo manager, property and declarative bindings, reference counting and automatic synchronization between clients and servers. It is design to always deliver high performance and low memory consumption.

Grunt is used for building the client-side code and deploying it. It uses models in the style of the Mongoose ODM, and most parts of the framework including models have event APIs. Views are implemented using view models.

The documentation at gnd.io includes more examples and demos.

Generators and Async Patterns in Node

Gorgi Kosev sent in his essay, Analysis of generators and other async patterns in node. He looks at how generators work, how the code compares to other implementations (for example, promises), using a complexity measurement, and benchmarks of memory and execution time.

The generator solution suspend is really fast. It incurred minimal overhead of about 50-80% running time. It's also roughly comparable with streamlinejs (when in raw callbacks mode).

Time Grunt

time-grunt (GitHub: sindresorhus / time-grunt, License: MIT, npm: time-grunt) by Sindre Sorhus displays the elapsed time of Grunt tasks:

// Gruntfile.js
module.exports = function(grunt) {  
  // require it at the top and pass in the grunt instance

  grunt.registerTask('default', []);