Did you ever use AngularJS as a frontend framework? Then you should definitely give Meteor a try! Where AngularJS is powerful just as a client framework, meteor is great as a full stack framework. That means you just write your code in one language as if there is no back- and frontend at all. In fact, you get an Android and IOS client for free. Meteor is so incredibly simple that you are productive from the beginning.
Where meteor kicks angular
One of the killing features of meteor is that you’ll have a shared code base for frontend and backend. In the next code snippet, you’ll see a file shared by backend and frontend:
[code language=”javascript” title=”A shared file used by backend and frontend”]
// Collection shared and synchronized accross client, server and database
Todos = new Mongo.Collection(‘todos’);
// Shared validation logic
validateTodo = function (todo) {
var errors = {};
if (!todo.title)
todo.title = "Please fill in a title";
return errors;
}
[/code]
Can you imagine how neat the code above is?
- As in the backend file and in the frontend file one can access and query over the Todos collection. Meteor is responsible for syncing the todos. Even when another user adds an item, it will be visible to your client directly. Meteor accomplishes this by a client-side Mongo implementation (MiniMongo).
- One can write validation rules once! And they are executed both on the front-end and on the back-end. So you can give my user quick feedback about invalid input, but you can also guarantee that no invalid data is processed by the backend (when someone bypasses the client). And this is all without duplicated code.
Another killer feature of meteor is that it works out of the box, and it’s easy to understand. Angular can be a bit overwhelming; you have to learn concepts like directives, services, factories, filters, isolated scopes, transclusion. For some initial scaffolding, you need to know grunt, yeoman, etcetera. With meteor every developer can create, run and deploy a full-stack application within minutes. After installing meteor you can run your app within seconds.
[code title=”Simple steps to install, run and deploy a meteor app”]
$ curl https://install.meteor.com | /bin/sh
$ meteor create dummyapp
$ cd dummyapp
$ meteor
$ meteor deploy dummyapp.meteor.com
[/code]
Another nice aspect of meteor is that it uses DDP, the Distributed Data Protocol. The team invented the protocol and they are heavily promoting it as “REST for websockets”. It is a simple, pragmatic approach allowing it to be used to deliver live updates as data changes in the backend. Remember that this works all out of the box. This talk walks you through the concepts of it. But the result is that if you change data on a client it will be updated immediately on the other client.
And there is so much more, like…
- Latency Compensation. On the client, Meteor prefetches data and simulates models to make it look like server method calls return instantly.
- Meteor is open source and integrates with existing open source tools and frameworks.
- Services (like an official package server and a build farm).
- Command line tools
- Hot deploys
Where meteor falls short
Yes, meteor is not the answer to all your problems. The reason, I’ll still choose angular above meteor for my professional work, is because the view framework of angular rocks. It makes it easy to structure your client code into testable units and connect them via dependency injection. With angular you can separate your HTML from your javascript. With meteor your javascript contains HTML elements, (because their UI-library is based on handlebars. That makes testing harder and large projects will become unstructured very quickly.
Another flaw emerges if your project already has a backend. When you choose meteor, you choose their full stack. That means: Mongo as database and Node.js as backend. Despite you are able to create powerful applications, Meteor doesn’t allow you (easily) to change this stack.
Under the hood
Meteor consists out of several subprojects. In fact, it is a library of libraries. In fact, it is a stack; a standard set of core packages that are designed to work well together:
- To make meteor reactive they’ve included the components blaze and tracker. The blaze component is heavily based on handlebars.
- The DDP component is a new protocol, described by meteor, for modern client-server communication.
- Livequery and full stack database take all the pain of data synchronization between the database, backend and frontend away! You don’t have to think about in anymore.
- The Isobuild package is a unified build system for browser, server and mobile.
Conclusion
If you want to create a website or a mobile app with a backend in no time, with getting lots of functionality out of the box, meteor is a very interesting tool. If you want to have more control or connect to an existing backend, then meteor is probably less suitable.
You can watch this presentation I recently gave, to go along with the article.