Posts In Category

Node.js

CQRSDDDEvent SourcingNode.js

Anyone learning about DDD, CQRS and/or event sourcing has probably read the source code of Greg Young’s simple CQRS example at some point or another. This is one of the simplest examples possible demonstrating the practical side of CQRS and event sourcing, originally developed using .NET. I made an attempt to rewrite the source code of this example using Node.js, trying to apply as many features of the core library as possible, particularly streams and

Read More
JavaScriptNode.js

Some time ago, I was watching this excellent video course by Neal Ford titled “Functional Thinking – Functional Programming using Java, Clojure and Scala”. In one of the modules on functional data structures, Neal talks about this container type in Scala named Either. The Either type in Scala represents one of two possible values, a Left value or a Right value.  The convention dictates that the Left value is used for error or exception objects,

Read More
Node.js

I was implementing a custom writable stream in Node.js the other day when I ran into this issue where I wanted to know whether more data was coming or that we were actually done writing stuff. When looking at the recently revised API for stream implementers, the only thing that gets mentioned in the docs is the _write method. After some intensive DuckDuckGoing (yes, this might become an actual word in the future), I ran

Read More
Node.js

Soon after I started using Node.js, I ran into the phenomenon of multiple nested callbacks that create some kind of horizontal tower effect. The solution I came up with in order to improve the readability of my code was using a library called step, as described in this blog post that I wrote at that time. Over the past years I switched over to a couple of other control flow libraries that solve the same

Read More
Node.js

Some time ago I was looking for a validation library/module for use in a small Express application that I was writing at the time. I couldn’t find anything that suited my taste so I decided to write one myself just for kicks. The goal was learning how to publish a module to npm and making a futile attempt to contribute something back to the vibrant Node.js community. node-validation is a minimal but slightly opinionated validation

Read More
Node.js

Last year I wrote this blog post where I described a couple of ways on how to tackle routing with Express. In the mean while I moved on from the “Plain Old School” approach to an approach where I replaced underscore.js with node-require-directory. Setting up node-require-directory is quite easy. In the routes folder, we just need to add an index.js module with the following two lines: var requireDirectory = require(‘require-directory’); module.exports = requireDirectory(module); Setting up

Read More
Node.js

Recently I added Twitter authentication to TrackMyRun using a library called Passport. I was pretty impressed how smooth this all went as I completely neglected all security concerns from the get go, which is definitely not recommended by the way. For this post I’ll walk you through the process of setting up Passport for Express using Twitter OAuth authentication. Passport is actually the core library which provides support for OpenId and OAuth authentication. Instead of

Read More
Node.js

In the previous post I wrote about my personal routing flavor for Express. For this post, I want to briefly discuss how to set up error handling using Express. In order to get up and going very quickly, we only need to add the errorHandler middleware provided by Connect. application.use(express.errorHandler({ showStack: true, dumpExceptions: true })); Here we configured the errorHandler middleware to report on exceptions and show the stack trace as well. This is quite

Read More