All posts by Luis Aguilar

Why is Node.js so Popular?

I am pretty sure you have heard about Node.js. Basically EVERYONE is talking about it right now; everyone wants to learn it, web development trends seem to be moving towards it and even huge sites like LinkedIn, eBay and PayPal have their entire infrastructure based on it.

Node.js is a server technology used to build and run web applications, similar to what ASP.NET, Ruby on Rails or Spring Framework does. It uses JavaScript as its main language, a built-in lightweight web server and a whole bunch of plugins managed through the Node Package Manager (NPM) that allows you to mold your application to your needs, like adding Model-View-Controller features, RESTful services, OAuth and SSL security and others.

But, really, why has it become so popular all of a sudden? Sounds like yet another web technology like any other else, right?

Well, in a nutshell:

  • Language re-use     Technologies like ASP.NET or Spring requires developers to know yet another language to write code on the server-side; be it C#, VB.NET, Java or any other. On the other hand, Node.js uses JavaScript both on the server and client side, meaning that developers only have to talk in a single language across all layers.
  • Easy developer transition    JavaScript is a common ground between web developers, that’s a known fact. Most of us know JavaScript or have used it at some point in time; of course, because of this, transitioning a web developer from any other web technology to Node.js is easy as pie.
  • It is lightweight    Node.js uses an event-driven architecture which means everything done on it, every single call and operation, is a chain of asynchronous callbacks. This allows Node.js to run on a single thread, different to other web technologies, which spawn a new thread per-client request. This is the very foundation of the non-blocking I/O nature you may have heard that is Node.js’ main feature.
  • Built-in support for object databases    It is really common for Node.js applications to use object databases such as MongoDB. MongoDB, contrary to traditional SQL databases, it uses a document-based model instead of a relational model; this means that instead of tables, it uses objects resembling JSON. Just the right answer for ORM fans.
  • Wide support from IDEs and code editors    JavaScript has been around for a long time, so code hinting and highlighting is featured by a bunch IDEs like Visual Studio and Eclipse; also editors like Notepad++ and Sublime Text.
  • Can be hosted almost anywhere    Several web servers and cloud-based hosting providers support hosting of Node.js web applications out-of-the-box. To mention a couple: Google, Microsoft IIS, Heroku, Microsoft Azure, Amazon (AWS), and a bunch others.
Node.js event-driven architecture. Image by

So, that’s my two cents on the matter. I’ve been getting my hands dirty with Node.js these last weeks and have been a hell of a ride. It keeps becoming more and more a necessity to learn its ways as time passes. I’ll be posting on my findings soon.

In the meantime, here is an interesting guide on when and where to use Node.js and, if its the case, how to convince your boss about using it for your next project.

Wishing For A Lazier Underscore

Sometimes the day of a developer gets awfully complicated. One of my less favorite moments are those when you have used a library for most of your project and then you realize you need things from it it was not designed to do. I was in this particular position last week, trying to stretch UnderscoreJS in ways it just wasn’t designed to bend.

Don’t get me wrong, I love UnderscoreJS, it brings the sweetness of C#’s LINQ-style chained queries to JavaScript arrays. If it was a person, I would totally hug it. But it made me smash my head against the wall a couple times when I realized that it lacks lazy evaluation of chained queries.

Why would I need that, you ask? Because sometimes I have to accomplish the darnest requirements. The original culprit was Kendo UI, an awesome UI-widget library by the guys at Telerik. The issue is that I had to completely override its built-in filtering mechanism since I needed it to be able to filter a data source in a master-detail fashion. For example, I have an array of customers, each customer has a sub-array of products it has bought. The grid displays a master row per-customer and detail rows for the products it has bought. Even so, the user should be able to filter by product, so if any customer had bought a particular product, it should be listed in the grid.

As long as I (and Google) know, this cannot be done out-of-the-box with Kendo UI unless you do it manually on server-side, since it can filter over all of the object properties, but not sub-arrays.

After some work, I managed to override the default filters and the original filter method in the grid’s data source. However, I needed a fast way to filter the data source like the original filtering mechanism did, so I recurred to UnderscoreJS. Performance was not that good; after wrapping the data source in an UnderscoreJS chain, I had to apply the filter method once per filter applied on the grid. The more filters, the worst performance got.

I eventually figured out that every time I was calling the filter function, it was iterating once over the entire data source. Of course performance was bad. Really dumb of me, since I was used to how LINQ worked; it allowed me to build a query in a fluent fashion and then execute it over the data source so it was iterated over just once. This process is called lazy evaluation of a query over a data source. UnderscoreJS does NOT feature lazy evaluation.

I think the only thing left to do is to use another library to support my custom filtering mechanism. Sigh. I’ll let you know of my findings…

CSS3 Pseudo-headache

So, the other day I was building a list for an HTML page.  I needed to change the font color of the last item in the list having the top  CSS class.

Here is my list, and its equivalent HTML structure with classes:

CSS Pseudo - Sample 1

Since what I wanted to do was merely style-related, I tought of only using CSS for it. After all, how hard could it be!? RIGHT!?

Anyways, after choosing to use CSS pseudo selectors for it, my first attempt was something like this:

Makes perfect sense, right? I mean: “from the list, select the last child element with list-item top  class and apply style to it.” Well, not so fast… Turns out it doesn’t work that way.

However, if you add top  to the only element that does not have it, everything magically works. Why is this? Apparently, CSS pseudo selectors handle classes a little bit different than I thought. My CSS selector reads a little more like: “from the list, select the last child element and apply the style IF it has the list-item top  class.” This means that if the last element in the list does not have that class, it will just skip it.

Of course, I could not style my list without using JavaScript or adding extra CSS classes to the element. It would be awesome if that CSS selector worked, since is not the first time I’ve had to do something like that. Sigh…



Hola Mundo!

Hi there! Be welcome to my blog, fellow internet user. A place where I’ll be sharing all sorts of interesting content (or a pretty good attempt at it) related to software development; ranging from tuts on edgy stuff and random snippets to rants and other assorted life lessons.

“Who the hell is this guy!?” you might be asking. Well, my name is Luis Aguilar, a software developer who loves best practices, architecture design, and all other sorts of hilarious stuff. Also, I’m from Costa Rica, better known as “that island from Jurassic Park”, “that other outsourcing country that is not India” or Puerto Rico.

Now, as a rookie blogger, be aware that your thoughts matter to me. If you have any feedback, suggestions, comments or if you just want to say hi, drop me a line through the contact form or to my e-mail.

In and out!