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
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.
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.
Give it a try and tell me what you think!