Habilelabs-Logo
Blog

Getting started with meteor packages (Install, Use and Build)

ByShankar Morwal
September 29th . 5 min read
Deploy guide Of Meteor.js

Getting started with meteor packages (Install, Use and Build):

What are meteor packages?

Let’s say you’re making your on a functionality and you realize that some of your functionality could be used in almost any app. In this case, we need to make you independent of your application and make it shareable.

In this case, you need to create a meteor package. This can be installed in any application and it will be working without no extra effort.

This tutorial will get you started on your first meteor package.

Create your first Meteor package:

atmospherejs is a central repository of meteor package, We create, download and publish packages from here. before getting started please create your account on atmospherejs.

Let’s start by creating a new meteor project.

meteor create pack
cd pack

Now we will create an internal package to this application. A Meteor project can have external and internal packages. External packages are directly user from meteor package manager atmospherejs.

Meteor expects ‘packages’ folder for internal packages.

Create a packages folder in the project folder.

mkdir packages
cd packages

In here we store all our custom made packages. Before we create one, we have to remember that the name of our package needs to be in a particular format: “username:packagename”, where username is your Meteor Developer username. If you still have created account on atmospherejs then please create an account. My user name is ‘morwal89’. So after this in this tutorial, I will be using this name. you can use your user name.

Now we will create one sample package.

meteor create --package morwal89:simple 

This will create a folder ‘simple’ and will create some files inside this folder. It creates packages.js, simple.js, simple-test.js. We will try to create a simple template.

Add simple-template.html

One Simple TEMPLATE

Create entry of this newly created file inside package.js. As this file is will load on the client we will use client tag.

  Package.onUse(function(api) {
  api.versionsFrom('1.4.0.1');
  api.use('ecmascript');
  api.mainModule('simple.js');
  api.use("templating", "client");
  api.addFiles("simple-template.html", "client");
});

Now we will need to add this new package to our application. Even this is internal package still we need to create dependency. without this, you can get errors like “lookup.js:189 Uncaught Error: No such template: simpleTemplate”

Run command following command in application root folder to add this.

meteor add morwal89:simple

We are ready. Now will reference this template in our application.

Edit the main.html inside client folder.

  pack

Welcome to Meteor!

{{> simpleTemplate}}

Run Meteor project.

You will on screen One Simple TEMPLATE on screen.

Publish your meteor packages:

Now we will publish this package on atmosphere.

You will need to login to meteor shell using the command line. Go to simple package root folder and log in on Meteor.

To login run

meteor login

This will ask you username and passwords. After login completed you are ready to publish your first package. run following command

meteor publish --create

Congrats your first package is published. Login to atmospherejs to see your first published package.

Still having a problem in this process? Let me know in comments sections. I uploaded the full source code for a tutorial on GitHub. Download this from Here . We are best wed development service provider

Hope you enjoy this post, so don’t forget to share with friends.

Share: