Archives For nodejs

When you’re developing web apps they tend to start out simple and then grow more and more complicated. On your servers you have services for your dependencies, but when you’re in development mode, it can be tricky to get everything running at the right time. The tool I’ll show you here works for Node.js, PHP, Java, Ruby, Python and more.

I use a laptop as my main computer and in order to save battery life, I limit the number of services I have running. A common app may be built with Node.js and rely on MongoDB and Redis. Therefore I launch MongoDB, launch Redis, then when all are running, launch my Node app. Then when I’m done I have to remember to shut each down. It’s a chore – exactly the kind of chore computers are great at, so let’s have the computer do it for us. Continue Reading…

“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…

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 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…

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…

According to the Jade website, “Jade is a terse and simple templating language with a strong focus on performance and powerful features.” Similar to Python, it uses indentation to help keep track of tag nesting which forces you to keep your markup looking clean. Because there are no closing tags, the end result is very concise. I suspect that if you used CoffeScript and Stylus, Jade would feel very comfortable.

Furthermore, it is the default template language enabled in new Express.js apps. Therefore it is commonly featured in beginners tutorials and documentation. At first glance I found it very confusing. The tutorial featured on the homepage is quite trivial, and therefore isn’t very representative of real-world work. However, there is decent documentation that you can dig into. You’ll find that much of the documentation focuses on standard HTML syntax and less on the dynamic capabilities.

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…

Recently I was using a Node.js library that incorporated EJS and I wondered what factored into the decision to choose that template engine over some of the others. I realized that because of my familiarity with Mustache, when I started using Node.js I immediately started with Hogan.js (see my tutorial on how to supercharge Hogan with Express) and I hadn’t checked out the other popular options. What are the differences between Jade, EJS, Hogan, Handelbars and JSHTML? I’d never used most of them in a real project.

I decided it was time to change that, and figured that if I were going to do the research I might as well share the results with you. I thought I could just make one long post but wow it turned out to be long so I’ve chosen to split it into 5 separate articles, which I’m linking below. Before we get into the specifics, let me take a moment to explain my biases and tell you what I value so you can use my comparisons to make your own decisions. Continue Reading…

As you may know, I prefer to use Hogan.js for my Express projects. Mustache, Handlebars and Underscore are also good. And actually, Jade is a very good framework, I just like HTML and find the Jade syntax abstracts that away. One thing I don’t like is old fashioned PHP-style logic and templates mixed together.

For that reason, template frameworks like EJS are definitely not my style. EJS not only allows you to mix Javascript into your templates, it essentially requires it. If you want to iterate or do an existence check, you need to write Javascript and stick it in your template. Ick.

What does this have to do with Sails.js? Continue Reading…

I’ve played with this for about 30 minutes now and my instincts tell me it is a great project. It borrows from the philosophies of other popular MVC frameworks such as Ruby on Rails and Backbone.js to create a server-side tool-suite to simplify the work of modern web developers, particularly front-end developers.

It’s called Sails.js and, from the fine manual: “Sails makes it easy to build custom, enterprise-grade Node.js apps. It is designed to resemble the MVC architecture from frameworks like Ruby on Rails, but with support for the more modern, data-oriented style of web app development. …Sails is especially good for building APIs, single page apps/sites, and realtime features like chat.” Continue Reading…

I’ve been poking around at Ghost, a new high-performance and light-weight blogging platform. If you follow the instructions to checkout the latest code from Git you may bump into the same issue I encountered, cryptic errors related to Sass and Bourbon. Fortunately, this is easy to fix.

The errors I received were:

Running "sass:compress" (sass) task
Running "shell:bourbon" (shell) task
Syntax error: File to import not found or unreadable: bourbon/_bourbon.

You must have the Sass and Bourbon gems installed local. After you’ve checked out the git branch simply run: sudo gem install sass bourbon on Mac or Linux to fulfill these requirements. Then follow the instructions in the contributor’s guide. To be fair to the developers, the instructions do list these as dependencies. However, it wasn’t clear to me how to fulfill them (I tried using npm at first which didn’t help at all). It was pretty effortless to get it working once I had the Gems installed. Continue Reading…