Grunt and RequireJS

I’m still working on the build process to speed up the actual build by requirejs in grunt. Currently the speed is about 20-25 seconds and I think that just to slow if a bug is found due to a build issue and debugging has to be done with the build itself.

For the production portion, I’m using a fairly basic require script structure which loads the common files, which then loads the backbone app loader which contains the app and base app. This limits the request down to 2 files and allows the common file to be loaded by itself on the homepage and on any page that isn’t using a backbone app but still requires jquery and other similar libraries. This structure allows for a faster load time, cacheable libraries but individual app files.

For the development portion, I’m using a different require script structure (determined by the application) which loads the backbone app, which loads the backbone base app, which loads the common file.

Continue reading Grunt and RequireJS

Node.js async with events in order

Previously I wrote about Bookshelf, a wonderful and fairly powerful ORM for the Node world (and javascript in general). Considering how new Node really is to the public, that I can do most major things in MySQL with a few simple files and commands is just amazing.

But sometimes you want to do things in an order but the order isn’t know because it hasn’t arrived (new request or websocket message).

In comes a super simple tool called kue.
Here is a tutorial.

This allowed me to use a utility class along with a reversed controller that could accept messages, filter them out and then queue them to be saved to a database. This was required because some messages were updates to previous updates, with out build a super large container with its own comparison system, this allowed the queues to be processed in order, the promises to “.then” handle when the job was done and trigger that so that the next job could be processed.

Continue reading Node.js async with events in order

Working with Bookshelf.

Bookshelf is an awesome ORM.
But the documentation is lacking in examples like non other.

I’m new to the Node world and almost all of these docs have the assumptions you know everything about Node outside of just this small function that the library provides.

First, since node is async, Bookshelf is also. Bookshelf uses promises (while others use callbacks).
This is great for a website but not great of a utility tool since you are dependent on the data being there before the next step.
So you have to wait for the ‘.then’ or the ‘fetched’ event (still figuring out how to use that…)

Example Code:

var newUser = {
'name': 'Joe',
'email': ''

new self.models.User(newUser).save().then(function (model) {

That looks nice and all, BUT, now you want to send an email, well you have to do that inside of the .save or have some kind of callback.
A way around this is emit another event.

Dealing with .fetchAll and collection.fetch

Getting Started with Bookshelf.js

Continue reading Working with Bookshelf.