Dockerizing Node Services

2016 Jan21

f you haven't jumped onto the docker bandwagon just yet, you are missing the boat. It has quickly become the de facto way for building, and deploying applications of all types and sizes. And it should be. It's easy to learn and makes deploying and scaling applications significantly easier. Linux containers are lightweight, start up very quickly, and are "throw away" resources. Most of all, Node.js applications are a breeze to get running containers

Set Up An App

The most common, and easiest way to create Docker images, is to use Dockerfiles. Much like a Makefile, Rakefile, Jakefile, etc, A Docker file is a simple set of instructions that is used to create the base image for you

Read More
filed under:  api docker node.js

Configure Node Apps with Nconf and ETCD

2015 Nov02

Recently, I have been working with, and learning a lot about the new distributed operating system, CoreOS. It is really interesting and makes managing micro-service architectures, quite a bit easier than manually SSHing into each machine and dealing every node individually. At the heart of CoreOS sits ETCD, a distributed key / value store. Internally CoreOS uses it for node discovery, communication and orchestration. Unlike other key / value stores, ETCD feels a bit more like a file system with directories and files. A directory can contain multiple directories and files where a file can contain a single value. For example, you might store the name of the environment as /company/metadata/environment = staging. It is a data hierarchy, which means it

Read More

Throttling Endpoints With Node-Tastypie & Hapijs

2015 Aug01

hen you decide to open up parts of your API to the public, you will need to prepare for bad citizens, or consumers that may abuse your API. One way to safe guard against this might be throttling certain endpoints restricting them to a certain number of request per second.

Throttle ['Thraudl] -n --noun., -v --verb

a device controlling the flow
to choke or suffocate in any way.

Tastypie's base resource has hooks for easily implementing throttling behaviors. The default implementations are mostly for testing and debugging be provide the just such a behavior, allowing you to define a number of requests allowed during a given time frame. Setting up is very easy, and looks something like this:


Read More
filed under:  tastypie REST hapi node.js

File Uploads With Node Tastypie & Hapi

2015 Jul24

ealing with files and handling uploads is an ugly reality in web applications. It can be even more unpleasant if you application is driven by REST APIs. In days passed, it often came down to flash uploaders talking outside the api and someone having to link multiple data sets together. I was always partial to the fantastic [FancyUploader Library]( Fortunately, things have gotten better. Node, and [Hapi]( make dealing with incoming files much easier. More over, Tastypie & Hapi make this exceptionally easy to do this in a single Api Endpoint. To illustrate this we are going to build up a small Api to store and save some binary data.

To accomplish

Read More
filed under:  api hapi upload rethinkdb node.js

REST APIs with Node Tastypie - Part 3: Custom Routes

2015 Jul21

e have been taking a look at how to use Tastypie to *easily* create robust, feature rich REST APIs. Our focus has been on CRUD operations, mainly because they are the ones that ship with tastypie. However, we are not restricted to *CRUD* with tastypie. You can define any number of endpoints to do whatever you want. To create a custom set of endpoints there are three basic things you need to do:

  • Define a route
  • Define a handler
  • Define Method Access

Last time we wrote a very simple resource that allowed use to just return simple objects. We are going to continue with that example by adding some custom routes to it. If you are joining in late,

Read More
filed under:  tastypie REST hapi node

REST APIs with Node Tastypie - Part 2

2015 Jun25

ast time we took a look at setting up a pretty full featured [REST api centered around Mongoose]( However, sometimes simple is better. Maybe you don't want and/or need all of the extra things that the MongoResource in [Tastypie]( provides. Sometimes you just want to get something, *anything* working and dump out some data. We don't need `paging`, `caching`, `filtering`, `validation`, etc. Luckily, Tastypie gives you a dead simple way to do this by simply defining the methods you want to support. Resource methods are defined as `_`. So a dumb crud resource would look like this:

The Simple Resource

var Resource = require('tastypie')
Read More
filed under:  tastypie REST hapi node

Functional Math With Closures

2015 Jun23

ven though javascript is the most widely used programming language in the world, people still bash it. *Closures are confusing and prone to errors*, people will often say. Which is a true statement. However, higher order functions and closures are one of the things javascript does best. It allows us bend the language to do some pretty interesting things.

In one situation, I pointed out one could create a function based math library and just dynamically create equations on the fly rather than having to hard code math logic all over the place, where all numbers and operations are functions that accept functions as arguments. Of course I was challenged on the fact - So, of course I had

Read More

REST APIs with Node Tastypie and Mongo - Part 1

2015 Jun12

EST Apis seem to be taking over the world as of late, and Node has been the platform of choice for building them. However, when you take a look at some of the tooling for building robust REST APIs in the node community, the options are bleak at best. When you take a look at all of the properties that would make an API RESTful, it is easy to see that it is rather complex.


There are a few fundamental properties that make apis RESTful - they should be a Scaleable, Stateless, Cacheable, fit into a Layered System which is apart of a Client / Server model that provides a Uniform Interface. In the confines of a Restful HTTP

Read More
filed under:  api tastypie node tast mongodb REST

Production Ready Node: Caching

2015 Apr29
aching is often times the first line of defense against poor performing applications and very quickly becomes a critical and complex part of various parts of the stack. One of the more frustrating aspects of caching, is that there are so many very capable solutions available - [redis](, [memcached](, `memory` etc. Even some `databases` or plain old `files` can be used to cache data in certain circumstances. Each of them having different strengths, weaknesses, uses cases and different APIs.

Cache ['kash] -n, noun; -v, verb

a component that stores data so future requests for that data can be served faster; the data stored in a cache might be the results of an earlier

Read More

Production Ready Node: Command Line Tooling

2015 Mar06

ommand Line tools are an important component to development, administration and maintenance of most all software projects - large or small. A good command line tool greatly speeds up repetitive operations through simple and flexible abstractions.

The Node.js community has a number of tools out there for quickly building out a command line interfaces, commander being one of the more popular. However, most all of them suffer from the same set of problems, making them difficult to integrate into applications in a clean an re-usable manner. Primarily speaking, there is no way to separate general functionality, from a command, from the argument parsing, or a command from the command line tool itself. This makes building for code re-use

Read More