Skip to content

Instantly share code, notes, and snippets.

@justrdk
Created March 23, 2016 21:12
Show Gist options
  • Save justrdk/6dc94d0ce710b7f0c7ba to your computer and use it in GitHub Desktop.
Save justrdk/6dc94d0ce710b7f0c7ba to your computer and use it in GitHub Desktop.

Meteor Meteor Meteor

Over the past years I've been working mainly on web applications, full stack (backend as well as client side code). We all go through the same steps to start our application.

  1. Setup server environment
  2. Setup client environment

I've been mainly working with Nodejs on the backend (feathers, hapi, express and sails lately) and I've really enjoyed it, especially now with all the ES6 goodies out there, and node V4 supporting a lot of them without flags on runtime. But One day I decided to try something entirely new, and that was the moment I met Meteor. I read the docs and went through their tutorial, The classic TODO Appm but what really got me was that there was no backend per-se, no models/services on my client requesting data from the server, no endpoints defined on a router and THEN I noticed the curious

if(Meteor.isClient) {
  //client side code here 
} 

and on the same file:

if(Meteor.isServer) {
  //server side code here 
} 

I was like, this is a totally new approach...the TODO app was super easy to follow on the tutorial and it was realtime out of the box thanks to Meteor's publish and subscription functions. If you were to do the same tutorial on any other framework like Angular, Ember, CanJS, React you would have to end up setting up the following:

  1. Setup server, for example express
  2. Define routes. POST/DELETE/PUT/GET for the TODOS stored
  3. Setup a local mongodb and connect your backend to it.
  4. Setup controllers/components/services/models on your client side which will call the required endpoint on your server.

Let me tell, I ended up doing none of those 4 things when I used Meteor. The only things I had to set up where the Insert, Update and Remove methods for the client to call, since this operations cannot be called directly from the client (security reasons) MeteorMethods.

If I wanted to create a TODO after clicking a button, I will easily bind an event to the button and then call the Meteor method responsible for creating the TODO, all this from the client side. No need to define routes for my calls from the client since Meteor methods will handle this for me, no need to setup a server on a different code base, since Meteor is all about the isomorphic approach, I didn't had to setup a mongodb since Meteor does this for me as soon as the app launches, and no need for models/services blah blah blah since I can Insert/Update/Find/Delete documents on my Mongo collections without all these steps.

You see when you create a Mongo collection on Meteor, it will exist both on client side and server side, take it like a global variable which I can all the same way across my app, no matter the environment I'm currently working on. And is even more amazin that everytime you do for example a findOne or findAll call from the client, you ain't even hitting the database. Meteor has these so called Optimistic UI which will create a minimongo on the client memory, which will contain the data that was publish from the server which the user on the client side will subscribe. Updates done to these collections will be mirror between the minimongo stored on the client's memory to the collections created on the server side (amazing ain't it?).

For me the greatest strength Meteor offers is how little setup you as a developer need to do, in order to start coding your application, heck I didn't even setup grunt/gulp files which will boostrap my dependencies etc..

It is still a growing community though and there aren't really defined patterns of how things should be done on Meteor, some people might me skeptical on combining server and client side code, but let me tell you it is amazing and you should definitely try it out.

P.S If you are an angular/react lover, Meteor plays extremely well with these two :). Not only Meteor is isomoprhic, check out Feathers as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment