The JavaScript blog.


database ORM iojs frameworks ES6 node express

Node Roundup: io.js 2.2.1, firenze.js, Express Happiness

Posted on .

io.js 2.2.1

io.js 2.2.1 has been released. The notable change in this release is the switch back to this.client in the IncomingMessage constructor in the http core module. The original change broke compatibility with request, which is used by npm. The io.js contributors found out about it by running make test-npm. There's an interesting discussion about it in the io.js pull requests.


Fahad Ibnay Heylaal sent in firenze.js (GitHub: fahad19/firenze, License: MIT, npm: firenze), an ORM for SQL written in ES6. It's built with Babel so it should work with Node 0.10.x and 0.12.x.

The API is promise based:

var posts = new Posts();  
posts.find('first', {  
  conditions: { id: 1 }
}).then(function(post) {
  var title = post.get('title');
  var postObject = post.toObject();
  var title = postObject.title;

To define a schema, you first describe a collection (table) and then a model:

var Posts = db.createCollectionClass({  
  table: 'posts',
  modelClass: function () {
    return Post;

var Post = db.createModelClass({ // or db.Model()  
  alias: 'Post',
  collectionClass: Posts,
  schema: {
    id: { type: 'integer' },
    title: { type: 'string' },
    body: { type: 'text' }

But you can also use cool ES6 syntax like this:

class Post extends f.Model {  
  constructor(attributes = {}, extend = {}) {
    super(attributes, extend);

The project has a lot more methods for querying and saving data -- take a look at the project's homepage to see the full documentation.

Express Happiness

Express Happiness (GitHub: andreas-trad/express-happiness, License: WTFPL, npm: express-happiness) by Andreas Trantidis is a framework built on Express that offers the following features:

  • A JSON route tree
  • Strictly defined, centralised error handling
  • Route permissions
  • Parameter validation
  • Automatic REST API documentation generation
  • Data mocking

Validation is automatic, which means each parameter a route receives is defined in terms of the type. The route tree looks like what you might expect: a list of paths with HTTP verbs that map to RESTful methods. Routes can also be dynamic so you can include parameters.

Because the error handling is all in one place it's a lot easier to manage than a basic Express application. You can easily define error handlers for 404, 500, and any other error codes, and the framework will send the right thing back to the client.

The validation performed by Express Happiness is done through validator, which is a popular and well-maintained validation module.


libraries web node modules express middleware

Node Roundup: io.js 1.6.4, npm Semver Calculator, mongots, Join-io

Posted on .

io.js 1.6.4, npm Semver Calculator

io.js 1.6.4 is out, as always check the io.js changelog for more details. According to the changelog, the notable changes in this version are fixes for openssl, timers, and some changes to make it build for Android devices.

Understanding semantic versions

In npm Weekly, #11, a really cool semantic versioning calculator is mentioned. If you've been writing versions like ~1.1.0 but don't completely understand what this means, the calculator will show you which versions the string refers to. The source is available here: GitHub: npm/semver.npmjs.com, and works using Browserify, Angular, and npm build scripts.

It uses npm-registry-cors-proxy.herokuapp.com to fetch package metadata rather than directly hitting npm. Presumably that's because npm's web API doesn't have JSONP or CORS (yet?).


If you're interested in MongoDB and TypeScript, then take a look at Prabhu Subramanian's mongots (GitHub: prabhu/mongots, License: MIT). The author says it supports everything MongoJS does and passes the same tests. It's not yet available on npm -- he's working on a stable version before releasing it.


Most of us concatenate scripts to reduce request counts, but what about piping them? Join-io (GitHub: coderaiser/join-io, License: MIT, npm: join-io) is a middleware component that allows you to specify script or link paths like this: /join:/lib/client.js:/lib/util.js:/lib/jquery.js. When this hits your Express server, join-io will stream each file to the browser.

The author has built this module on top of files-io, which is a more generalised API for piping collections of files. And, naturally, files-io is written with pipe-io!


testing express middleware docker

Dockunit, easy-livereload

Posted on .


Dockunit (GitHub: tlovett1/dockunit, License: GPL, npm: dockunit) by Taylor Lovett is a Node command-line tool for running tests in Docker containers. You can define a set of containers for tests to run against, which makes it running tests against multiple environments a lot easier.

This is useful if you maintain open source projects. For example, a blog engine could be tested against Node 0.10.x and 0.12.x, or you could even switch framework versions for Express/Rails/Django/etc.

The author includes examples for PHP, Node, and Python, and it seems like you could hook it up to a CI server easily enough.


Are you still searching for the perfect Express middleware for live reloading your app? Daishi Kato sent in easy-livereload (GitHub: dai-shi/easy-livereload, License: BSD, npm: easy-livereload), a new module that uses LiveReload protocol 7.

If you haven't seen it before, then you might want to check out the LiveReload homepage. It's basically a protocol for updating client-side assets. With Daishi's module, you'll get almost instant updates to client-side assets, but also server restarts as well.

Server restarts are managed with node-dev. One interesting thing about node-dev is it's compatible with node-notifier, so you can get desktop notifications when the server restarts.


libraries node modules express connect iojs json-schema

Node Roundup: Unifying Node with io.js, JSON Object to JSON Schema, conveyor-belt

Posted on .

StrongLoop on Unifying Node with io.js

The StrongLoop blog has a post by Issac Roth about the unification of Node and io.js:

Unification is something you can help with! The io.js repository and the Node Google group are open to all. Get involved, post issues and comments, let people know your ideas and solutions. Tell people where you stand on the issue. I've worked with all of the contributors in small or large ways and they are each kind people--if they hear from a wide swath of the community something you want, it will surely get considered, as everyone I've met likes to serve the community.

Issac is involved with both the Node Advisory Board and Node Forward. Bert Belder, also at StrongLoop, is also involved with these groups as well, and works with Issac. This post gives a good insight into what's happening with Node and io.js, which is sometimes bewildering to outsiders, particularly if you pay attention enough to see core contributors switching to io.js with seemingly no explanation.

And, according to Issac, the technical divergence between the projects might not be as extreme as some people make out:

Having witnessed some of the early discussions between the io.js technical committee and the Joyent contributors, there are only a small number of points of disagreement on both governance (stuff like how voting would happen if needed) and technical decisions (stuff like which version of v8 to use in the next release.)

He ends saying that he's confident that we'll end up with a single Node project. I don't personally have a problem with forks existing, but it would make my life easier if I only had to write about one "Node".

JSON Object to JSON Schema

Nijiko Yonskai, who has sent in several small but perfectly well-formed Node modules, has recently published JSON Object to JSON Schema (GitHub: Nijikokun/generate-schema, License: MIT, npm: generate-schema). This project helps you to convert JSON objects to schemas:

var GenerateSchema = require('generate-schema')

  "_links": {
    "self": {
      "href": "/gists/42"
    "star": {
      "href": "/gists/42/star"
  "id": "42",
  "created_at": "2014-04-14T02:15:15Z",
  "description": "Description of Gist",
  "content": "String contents"

This outputs an object with the types based on the content, so in this case it's mostly { "type": "string" }. I've recently been creating JSON schemas from existing JSON data sets, so this would have made my job easier!


Svilen Gospodinov sent in conveyor-belt (GitHub: svileng/conveyor-belt, License: MIT, npm: conveyor-belt). It's designed to switch client-side assets based on the current environment, so you can easily load development mode client-side scripts with lots of logging.

It looks like it'll work well with Connect/Express-based applications, but you could use it with other frameworks as well.


libraries node modules express middleware oauth

Easier OAuth with Grant

Posted on .

OAuth always seems like an attractive alternative to rolling your own authentication, but it usually ends up being much harder than it looks. Grant (GitHub: simov/grant, License: MIT, npm: grant) by Simeon Velichkov aims to solve this. It's built on Guardian.js, which was made by Nijiko Yonskai at Mashape (Nijiko has written quite a few Node modules that I've written about).

Grant is Express middleware that accepts options for the OAuth server. You can include things like the permissions you want to request, so for Facebook this might include friends_groups:

"facebook": {
  "key": "...",
  "secret": "...",
  // by default request publish permissions via /connect/facebook
  "scope": ["publish_actions", "publish_stream"],
  // set specific callback route on your server for this provider only
  "callback": "/facebook/callback"
  // custom override keys
  "groups": {
    // request only group permissions via /connect/facebook/groups
    "scope": ["user_groups", "friends_groups"]
  "pages": {
    // request only page permissions via /connect/facebook/pages
    "scope": ["manage_pages"],
    // additionally use specific callback route on your server for this override only
    "callback": "/pages/callback"

One nice touch is you can provide options for different environment, so it's fairly easy to add settings for development or a CI server. Simeon has an app on Heroku that allows you to try out each provider with a friendly form: https://grant-oauth.herokuapp.com/.

I also noticed the same author has written a REST API wrapper called Purest. It embeds configuration details for dozens of providers, including Tumblr, Twitch, Google, and imgur.

To use it, you have to create an access token, then you can connect to a provider:

var Purest = require('purest');  
var google = new Purest({ provider:'google' });

google.get('channels', {  
  api: 'youtube',
  qs: {
    access_token: 'token',
    forUsername: 'user'
}, function (err, res, body) {});

This Google instance can be used to access YouTube's API:

    forUsername: 'username'
  .request(function (err, res, body) {});

The documentation includes an excellent example that uses the request module's streaming API to pipe files from one service to another.