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.

Node.js, PHP, NGINX and WebSockets (Socket.IO)

Don’t try using Express.IO. Just wasnt working.

Tech Used:
Centos 6.5 :
Nginx :
Redis :
PHP 5.5 :
Node.js : :
Angular JS :
Angular Socket IO :

Angular Socket IO Info:

Socket.IO works. But you have to understand what its doing. (I’ll explain further down)

Quick Info on Event Emitters:

Node.js Events and EventEmitter

Using Nginx to reverse proxy a secure apache site that is using

Loading a configurations in Node.js

Managing config variables inside a Node.js application

Continue reading Node.js, PHP, NGINX and WebSockets (Socket.IO)