Toggle Menu

Insights / Tech Tips / Node.js Challenges: Why MEAN Doesn’t Work, But a Hapi “LEBRON” Does

September 17, 2014

Node.js Challenges: Why MEAN Doesn’t Work, But a Hapi “LEBRON” Does

3 mins read

When I first started working with Node.js, the MEAN stack seemed to be the most popular and sensible stack to roll with. The MEAN Stack is MongoDB, ExpressJS, AngularJS, and NodeJS. I’ve spent a lot of time looking for good seed projects and examples of these technologies working in harmony.

After my trip to NodeConf this past summer, I got a chance to see what the Node community is doing and I was introduced to some new and simpler packages that make working with Node a pure pleasure. Since NodeConf, I’ve been working on a stack that makes it much easier to use and teach Node. I call this stack Hapi LEBRON. LEBRON is a combination of LevelDB, Browserify, and npm. Hapi is a rich applications and services framework built by Walmart Labs.

You might want to check this out if you are interested in rapid prototyping, doubled developer productivity by streamlining development technologies and real-time, highly concurrent or high I/O applications.

Keeping the Promise

Working with a full stack JavaScript solution carries a promise: no context switching. This is a very important promise that has huge productivity, maintainability and staffing implications. A lot of the MEAN code I’ve seen out there trades the problem of using different languages on the backend and frontend with using vastly different libraries and patterns between the two. JavaScript is a dynamically typed language, so by using different libraries and patterns the developer still incurs a costly context switch.

The biggest context switch happens in dependency injection. Node uses Require and most frontend developers use RequireJS. However, these two libraries work very differently and they’re not cross-compatible. So a module written for the frontend is not usable in the backend. Browserify solves this problem by enabling Node style which require statements to work in the browser. You can then leverage npm to its fullest extent by sharing packages between the frontend and the backend. The code-sharing benefits of Browserify alone can be very significant, but keeping the same basic file structure is… priceless.

Keep it Simple

Express is a step above manually configuring ports, but otherwise quite low-level and verbose, if you aim to write a Web API and serve web content. This is where Walmart’s Hapi comes into play. As best put in their website’s tagline, “Hapi enables developers to focus on writing reusable application logic instead of spending time building infrastructure.” It is very straightforward to write a capable Web API using Hapi quickly. I highly encourage you to give it a try.

Another area where complexity can easily creep into your application is by using a full on database solution. MongoDB is lot simpler than Microsoft SQL Server to install and maintain, but it still can be a barrier to learning and quick deployments. LevelDB is a fast key-value store that requires no setup or installation and can be used to persist data without hassle. It can be easily required using the level package. Level supports sophisticated range queries and covers use cases that a vast majority of apps would need.

 Separate Concerns

Most MEAN code I’ve seen utilizes Jade to generate Angular pages on the server. This is troublesome in many aspects and I’ve detailed my concerns on server-generated pages in my MVVM vs. MVC article on DevPro. The issue boils down to a separation of concerns, performance and code portability. By leveraging Browserify and utilizing Angular to write a discrete client, you can create a flexible architecture that can grow alongside your needs.

It is indeed possible to have a harmonious full stack solution based on open standards, enabling great skill sharing and attracting top talent to work on the latest and greatest technologies. No matter the mix of libraries in use, currently JavaScript and Node are the only technologies that can enable this in your organization.

Give it a try and tell me what you think!

You Might Also Like

Resources

Simplifying Tech Complexities and Cultivating Tech Talent with Dustin Gaspard

Technical Program Manager, Dustin Gaspard, join host Javier Guerra, of The TechHuman Experience to discuss the transformative...

Resources

How Federal Agencies Can Deliver Better Digital Experiences Using UX and Human-Centered Design

Excella UX/UI Xpert, Thelma Van, join host John Gilroy of Federal Tech Podcast to discuss...