Photo Credit: Cayusa

It’s quite common to create an app where you want to protect numerous pages. It’s not difficult to check for req.user and force the user to a login page, but code duplication is not a good idea. Fortunately, it’s quite easy to write a middleware that will require authentication for a whole set or URLs.

First, we’ll set some assumptions: You’re using Express 4.x, you’re using router (is there any other way?) and you’re probably using Passport. I don’t think Passport is required for this solution, but it’s the only option I’ve tested with. Let’s assume that you’ve got a homepage that does not require authentication but the rest of your site, other than the login/logout/register pages, require authentication. Continue Reading…

Photo Credit: dzarro72

Recently I built a demo application using Sails 10.x (currently in beta) and needed to add authentication support to it. One of the challenges with this is that the documentation for the beta Sails is not complete yet, and much has changed. The documentation is still great, so I definitely recommend making it your first stop.

While browsing through NPM modules I found sails-generate-auth which looked like an excellent solution for authentication. Yes, it works, but unfortunately the documentation is not written very well. The Github page makes it look like all you need is a configuration file and you’re set. In reality, there is a bit more work to do. Here are the steps I took. Continue Reading…

I’ve been so busy writing a Node.js training series that I’ve hardly had time to blog. I have several posts in the works but they’re coming slowly as I get the draft done and off to the publisher for review. I’ve learned some amazing tricks that I need to share and I also need to update a few blog posts that are getting a little dated. Stay tuned!

ipad-3-retina-display1

Apple is replacing Lucida Grande with Helvetica Neue in Mac OS X. Some people are happy, some are sad. Those that are sad explain that Helvetica Neue doesn’t make as good of a screen font because, in part, it has tighter apertures, which means that at small font sizes some letters get hard to read. For example, lower case Cs look like Os and Ss look like 8s. This is true when you view them at lower resolutions, such as most computer monitors (which are under 150 ppi, but is fine on high resolutions such as print outs (300+ dpi) and retina displays (approximately 300 ppi).

We know Apple cares deeply about the usability of their products, and we know that they have some great designers working for them, so we have to believe that they understand this potential for a problem. But what if the designers knew something we didn’t, that soon, non-retina displays would be obsolete? Continue Reading…

Photo by coolinsights

I often get asked by teens and parents for ideas for jobs. I always answer, “you should start a business.” Usually I’ll include suggestions based on what I know about the person who is looking for work. In my opinion, there is no better time in life to start a business than as a teen.

Why? You may ask? Well, here are a few reasons:

  1. No one is as risk tolerant as a teen
  2. Few people are as undervalued
  3. Learning to fail (aka trial and error) is one of the most important lessons you can learn and it’s better to learn it when you are young and the stakes are low
  4. You can make way more than minimum wage and you’ll more likely be doing work you enjoy

I could prattle off a few more reasons, but let’s dig into these. Continue Reading…

Sky-is-awake

My daughter finally got me to watch Frozen with her this weekend, and I have to admit, it is good. (we bought it on Amazon Instant Video, which is just too convenient in the post-DVD world) The voice acting and music are superb, the animation is among the best, but my favorite is the story, particularly three elements which deeply illustrate and reenforce important Biblical messages.

I want to warn you that this article does reveal part of the ending, so if you don’t want it spoiled, quick, go watch it now, then come back and read this. (I will still leave much as a mystery, so if you want to keep reading, you will still enjoy many surprises in the movie) Continue Reading…

Handlebars.js

“Handlebars” is a nickname for a fancy mustache. This pretty well embodies how Handlebars.js is a superset of the Mustache template library. Superset means that it has all the features of Mustache plus some extras. Like Mustache, Handlebars is a logicless template library. If you use a logicless template system after using tools like ASP or PHP you may feel there is a lot missing. It takes a little adjusting to, and one nice thing about Handlebars vs Mustache is that it makes the transition a little easier and more graceful.

Prior to my research for writing this series, Mustache was my favorite. I do still highly recommend it, but now I will be switching my work to using Handlebars.js. It has everything I like about Mustache, but it has a little better Javascript support, especially on the server side, and the conditional syntax is a little easier to use.

By the way, this is one part of a 5 piece series, so if you want to explore other options, don’t forget to visit the series start where I explain the biases and summary information and link to all of the tutorials.

Continue Reading…

Hogan.js

Mustache is described, simply, as “logicless templates.” The first time I used mustache I was pretty surprised at how minimalistic it was. And by surprised, I mean frustrated. You have extremely basic conditionals, an iterator loop and the ability to display information. There is no “if” (per se), no ability to call functions, mustache is not in any way a programming language.

You may think there is a lot missing, and there is, but this is not bad. It forces you to keep your logic all in one place, in the program. This increases the manageability of your code-base. It also allows Mustache to be easily ported to many programming languages. You can use it with Javascript, via Hogan.js, the library I used in this example, or Java, PHP, Ruby and numerous other languages.

By the way, this is one part of a 5 piece series, so if you want to explore other options, don’t forget to visit the series start where I explain the biases and summary information and link to all of the tutorials. Continue Reading…

jshtml

JSHTML provides an adaption of the razor view engine in Javascript. If you’ve used the Razor view engine for .Net languages then this could be the right template for you and your Node.js project. However, you’ll have to be more tenacious than I am, because the version bundled with Node.js is broken.

As a matter of fact, this will be quite a short review because I couldn’t find enough redeeming qualities to warrant the extra work to get it integrated.

By the way, this is one part of a 5 piece series, so if you want to explore other options, don’t forget to visit the series start where I explain the biases and summary information and link to all of the tutorials.

Continue Reading…

Screen Shot 2014-01-08 at 7.59.38 PM

EJS “cleans the HTML out of client-side templates.” From that description, you’ll quickly realize that EJS was at first a client-side template library. It has been repurposed successfully to also be a good server-side client library for Node.js.

In my opinion, using the word “clean” in the same sentence as EJS is a bit misleading. It does have the benefit of being included as part of the Express library for Node.js, which makes it easy to get started with, however like some other libraries, it lost functionality when Express made the jump to 3.0.

By the way, this is one part of a 5 piece series, so if you want to explore other options, don’t forget to visit the series start where I explain the biases and summary information and link to all of the tutorials.

Continue Reading…