Introduction

In case you missed the other days:
Day 1 Deep Dive
Day 2 Deep Dive with MongoDB
Day 3 Deep Dive with MongoDB
Day 4 Deep Dive with MongoDB
Day 5 Deep Dive with MongoDB
Day 6 Deep Dive with Mongoose
Day 7 Deep Dive with Clustering
Day 8 Deep Dive with PM2

On the flight back from California last night I queued up a few Node.js videos on YouTube for the flight, one of which was a presentation by Kim Trott of Netflix discussing Netflix's migration from a Java backend to node.js. I really enjoyed this presentation because it went over not only what worked great, but what didn't - something that doesn't happen too often especially from a larger company. Another highlight for me was reviewing some of the node modules Netflix uses to provide the millions of hours of content daily. One of which was restify. Restify provides a clean interface for routes without the templating and rendering that Express offered - which in my current testing fits much better.

Prerequisites

As mentioned previously, this point I am going to assume MongoDB is up and running, if you do not, check my first day post for details on how to get it up and running.

restify

To get started with restify you will need to install via:

npm install restify -g

In diving into restify I found another module that goes hand in hand, restify-router. As detailed on the aforementioned link, this module offers the ability to have more separation for all of the routes (similarly to those coming ASP.NET like myself who are used to specific *Controller.cs files per grouping of routes).
To get going with restify-router simply install it via:

npm install restify-router -g

I should mention I have removed the worker.js from the git folder for Day 9 as I am now utilizing pm2 as mentioned in yesterday's post.

Replacing the Express code with restify was pretty painless:

var restify = require('restify'); var settings = require('./config'); var testRouter = require('./test.router');  var server = restify.createServer(); testRouter.applyRoutes(server); server.listen(settings.HTTP_SERVER_PORT);

For those following my deep dive this should look very similiar to the Express code with the addition of the testRouter reference which I will go over below.
As mentioned above, I chose to utilize restify-router to split out my routes into their own files. My test.router:

var Router = require('restify-router').Router; var router = new Router(); var Post = require('./dbFactory'); function respond(request, response, next) { var argId = request.params.id; var newPost = new Post({ id: argId, likes: 2 }); newPost.save(function (err) { if (err) { return response.json({ message: err }); } return response.json({ message: true }); }); } router.get('/api/Test', respond); module.exports = router;

Similiarly there is not much difference from how the older route definitions, the only big difference is the first line requiring the restify-router module.

Next up...

As mentioned last night I am still investigating why on Windows only one worker process is getting hit verses utilizing all of them. I tested this on my i7 desktop and had the same results as my 2014 Razer Blade. I hope to further deep dive into restify tomorrow night and hopefully resolve the weird scaling issue I'm noticing.

All of the code thus far is committed on GitHub.
TAGS
none on this post