Recently I turned to Grails and delivered several projects with it. When developing with Grails you can use the power and the expressiveness of Groovy to write compact, elegant, fluent and readable code.
The downside is that Grails is huge:
- even the most simple Grails apps will weigh in the 40MB range
- compilation, test and building takes a long time (minutes, actually) even in recent versions
- it is (fairly) complex, but that I can understand because it does so much
- it will consume a huge chunk of you app server memory when deployed
I have been using Grails as the backend for Mappu too, initially just because I wanted to bootstrap the project quickly and Grails is simply perfect for that. But as time passed I started to find Grails too heavy for a simple REST API. I am currently running the demo on the smallest Rackspace server and it's constantly swapping. It's not slow, but it could be better.
Node, when combined with Express, is basically another MVC framework, only leaner than any I've seen in Java (well, maybe Struts in the early days was lean too). Also Node+Express gives you a very low level access to the HTTP layer, which feels quite weird for Java devs as most Java frameworks put numerous layers of abstraction between the HTTP protocol and the application.
So all this just to tell you that this week I started rewriting the Mappu API in Node+Express. My Javscript skills are in a pretty good shape and it was easier than I thought.
The major differences I stumbled upon were:
- POSTs are handled differently than GETs by Express. Surprisingly (well, for me) POST params are stored in the req.body property, whereas GET params are stored in req.params. It took a couple of hours before I figured this out and I felt pretty dumb afterwards
- there is no standard for almost anything: in Java the ecosystem has grown and stabilized (actually it shrunk) so picking, say, an authentication authorization framework is a straightforward process. Node.js is quite the bazaar as there are hundreds of modules to choose from (all on github, btw) for pretty much anything. So now, when I look at my package.json file I think (and worry): how many of these modules are actually still going to be maintained in the next 6 months?
- asynchronous callbacks felt weird at first, but I got over it pretty quickly
The (big) advantages over Grails are:
- speed: running all (integration+unit) tests takes 141 ms, and I have a lot more in Node+Express! In Grails it took minutes. I dare not do the math on wasted time.
mess withextend pretty much anything and this is a powerful feature. Forget about interfaces, abstract classes, private functions, protected members and all that. Of course with great power comes great responsibility so you and I have to be careful not to abuse this power and craft spaghetti code
- low level: you can work around pretty much anything, for instance gracefully handle database errors by retrying a couple of seconds later. You can do the same in Grails too but it is harder because of the Hibernate ORM layer
- it is ready for the cloud. Seriously, believe the hype. I will explain another time
Time to go now, let me know what you think in the comments.