Richard Gould

CTO, Software Developer, Language Learner

5 Steps to Understanding Meteor Better by Improving Your JavaScript

| Comments

I don’t believe you need to be a JavaScript expert before diving into Meteor, but I highly recommend taking the time to learn advanced topics first. By levelling up your JavaScript, you will understand the concepts faster, and will feel less frustrated and confused. Even if you don’t stick with Meteor or do Meteor full time, the skills these books will teach you will help you in all aspects of development.

I recommend starting by watching a series of Douglas Crockford’s lectures on JavaScript, and then following it with Reginald Braithwaite’s Javascript Allongé.

  1. Watch Crockford’s The JavaScript Programming Language. Watch it even if you already have built some applications with JS already. It goes into the fundamentals in-depth, and will help cement the basics in your mind, which is essential when learning advanced topics.
  2. Watch Crockford’s Theory of the DOM. Watch it even if you think you know the DOM well. Again, establishing fundamentals makes learning advanced topics easier.
  3. Watch Crockford’s Advanced JavaScript. It covers some advanced topics sometimes unique to JavaScript, and common advanced patterns. If you’ve ever tried reading a JavaScript library and couldn’t even begin to comphrehend it, this lecture will help clear things up.
  4. Watch Crockford’s JavaScript: The Good Parts. It will help you pick out the best parts of the language to use, and the parts that you need to actively avoid.
  5. Read Reginald Braithwaite’s JavaScript Allongé. Reginald (aka ragnwald) covers advanced functional topics, and this will permanently change how you write your JavaScript, enabling you to write resuable code faster and with much higher confidence.

I recommend doing the above in that order. Allongé is more advanced and builds off of topics covered by Crockford. Each step will help bring your JavaScript game to the next level, with Crockford’s lessons establishing solid fundamentals, and Allongé teaching (in a very effective manner) the more advanced usages of functional programming with JS.

Note that I did all of the above (and worked through the exercises in Allongé) before I even touched Meteor, and for the most part, the only Meteor help I’ve needed has been the official Meteor docs. Having such a solid foundation of knowledge let me pick up Meteor with lightning speed, and all of those skills will stay with me when it comes time to learn another framework.

If you have trouble following Crockford’s lectures, then I recommend reading his print edition of JavaScript: The Good Parts instead. While you’re reading it, really work through the examples to make sure you’re understanding it as you go along.

Have you ever felt that your JavaScript skills were inadequate? Have you ever looked inside one of the libraries you use (jQuery perhaps?) and felt as though you didn’t understand JavaScript at all? I want to hear about it. Email me with your story (write as much or as little as you’d like).

Disadvantages of Using Meteor (Over Rails)

| Comments

You can save significant amounts of time by developing some web applications by using Meteor instead of Ruby on Rails, but it doesn’t come without drawbacks. Here are some of the ones that I’ve encountered: What are the disadvantages of using Meteor compared to Ruby on Rails?

Immature Environment: The biggest problem right now is that Meteor is new. Pretty much brand new, in the scope of web development. It’s not even version 1.0 yet, though it’s getting close. This means that it doesn’t have as many users, as many tutorials, as many books, as many screencasts. It can be hard if you run into a problem that no one else has run into yet, so you’ll need to be willing to dig into it a bit yourself. I’ve been there, and fortunately Meteor’s codebase is fairly cleanly written (especially compared to Rails and AngularJS, two other frameworks whose code I’ve read).

Not Widely Supported: Another consequence of being so new is that there aren’t as many hosting services available for Meteor apps yet. It is possible to deploy Meteor on Heroku, and in my experience it works well, though it feels very raw.

Nothing but JavaScript: You must run JavaScript (or Coffeescript) on the server side. This isn’t a big deal for me, but JS is definitely far from the first language I would choose to work with. The upside is that you can run the same code on the server and the browser, without worrying about having to cross-compile from another language.

Only MongoDB: As of now, the only supported database is MongoDB. They have plans to expand this in the future.

Rapidly Changing: The Meteor API is rapidly changing, so each new minor version may bring breaking changes. This is expected to lessen as it reaches 1.0.

Testing Frameworks: Testing frameworks haven’t been a high priority since the beginning, and the ones available so far have tended to be cumbersome and brittle. The community is working on solutions, but nothing stable has yet emerged, and the testing culture is nothing like the Ruby on Rails community’s.

While there are many disadvantages, I feel like the advantages heavily outweigh them (usually). But the list of advantages is for another post entirely!

What are some other disadvantages you can think of? Email me or leave a comment!

Implementing Web Hooks With Meteor

| Comments

It’s possible to add web hooks to your Meteor application by using iron-router.

Declare a server-side route in your Routes.map declaration:

    Router.map(function() {
      ... // Your other routes go here

      this.route('hook', {
        path: '/hook',
        where: 'server',
        action: function() {

          // Watch the Meteor log to see this output
          console.log("Hook called.");
          console.log("Headers: ", this.request.headers);
          console.log("Data: ", this.request.body);

          this.response.writeHead(200, {'Content-Type': 'text/html'});
          this.response.write("You wrote: " + this.request.body.message);
          this.response.write("\n");

          // `this.response.end` *must* be called, or else the connection is left open.
          this.response.end('Success!\n');
        }
      });

    });

To test it out, issue this curl command from the command line:

    curl -H "Content-Type: application/json" -d '{"message":"foo"}' http://localhost:3000/hook

The documentation for this.response and this.request are available on the node.js website: http://nodejs.org/api/http.html

I’ve created a sample Meteor application demonstrating this, which you can view at https://github.com/rgould/meteor-posthooks

Not clear enough? Send me an email at rgould@u2622.ca for some more help!