This page looks best with JavaScript enabled

MeteorJS - Getting Started

 ·   ·  ☕ 3 min read

Meteor is quite an easy Javascript framework to pick up and I have been fascinated getting back to where I left off a couple of years ago.

There are quite a few things that you could do in the first week itself, and could even target to complete real-world projects.

However, be aware - MeteorJS is a ghost town of sorts.

The usage has declined rapidly over the past three years, and most of the content that you will find is outdated. Students of the framework will find older tutorials that do not quite work. For all my hubris, I still ended up spending time on debugging silly problems that should not have existed in the first place.

One of the popular tutorials of MeteorJS from LevelupTuts is on YouTube - Meteor for Everyone.

The tutorial can get you started quickly, but the framework itself does not quite recommend writing in the “older” way anymore. You’ve to make small amends to follow along if you choose to use the tutorial anyway - below paragraphs should give you a good idea on the changes.

Folder Structure

Create the following structure that can be beneficial for later.

  1. client (accessible only for the client - created automatically )
  2. server (accessible only for the server)
  3. lib (common for both)

If you follow a specific structure (which is highly recommended in Meteor), you may not do the following each time -

1
2
3
4
5
if (Meteor.isServer) {
}

if (Meteor.isClient) {
}

You may also see a reason to remove the main.js file references in package.json, or change references to point to your own files. This will avoid errors that tell you about required main.js files in client and server.

Create Collections

The tutorial talks about creating a collection called ‘Resolutions’. The code outlined in the tutorial will not work unless you import ‘Resolutions’ on the server side.

A file ‘main.js’ gets created automatically in the server folder when you create a new project through meteor create in recent versions.

Include the code below in [server folder] > main.js.

1
2
3
4
5
6
import { Meteor } from "meteor/meteor";
import { Resolutions } from "../lib/collections";

Meteor.startup(() => {
  // code to run on server at startup
});

Instead of creating a collection within a client-specific JS file (as outlined in the tutorial), create a new file called ‘collections.js’ under the ‘lib’ directory (you did create the folder structure outlined above?)

In collections.js, include the following code -

1
Resolutions = new Mongo.Collection("resolutions");

Lastly, in the ‘js’ file for the client (e.g., ‘main.js’ in client folder), include -

1
import "../lib/collections";

There some funny ways to do the above in the ‘new way’, but let’s keep things simple for all learners.

Stay in touch!
Share on

Prashanth Krishnamurthy
WRITTEN BY
Prashanth Krishnamurthy
Technologist | Creator of Things