Meteor Generate - A Rails Inspired File Generator for Meteor
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Generate Scaffolding for Meteor


The layout in master will be changing soon. This new structure is geared towards promoting components and moving away from Iron Router's controllers. Instead that logic will be in the component/page scripts.

Checkout the Yo generator for the new progress. Eventually mgen will run this beind the scenes to give you a cleaner CLI API than Yo.

In the future you can pin the release or run a local copy for legacy apps (I have it alised until I can migrate them).

Automate the common tasks used when building a Meteor app. Create 'pages', components, controllers, collections & more. User customizable templates and configuration. Meteor Generate borrows a few conventions from Rails but it still stays true to Meteor.


sudo npm install meteor-generate --global


mgen create <project_name> Runs Meteor create command and scaffolds out a basic app structure. mgen create myblog creates the following files:

└── myblog
    ├── both
    │   ├── lib
    │   │   ├── _namespaces.js
    │   │   └── collections.js
    │   └── routes.js
    ├── client/
    │   └── _startup.js
    │   └── main.html
    │   └── styles/
    │       ├── _components.scss
    │       ├── _pages.scss
    │       └── main.scss
    ├── server/
    ├── .jshintrc
    ├── .jshintignore
    ├── makefile
    └── smart.json


mgen component <name> Re-useable widgets that are not tied to a page. These should be able to be included in any page on the app. These are typically things like the header, footer, etc... Appends the Sass import into the styles/_components.scss file. mgen comp header outputs the follwing:

└── client
    └── components
        └── header
            ├── _header.scss
            ├── header.html
            └── header.js


mgen page <name> <action> Create conceptual 'pages'. Creates template, script, and stylesheet. No controllers are generated. If no action flag is passed in, all actions will be created. Possible actions: index, show, new, and edit. See Example Pages - mgen page posts --index creates the following:

└── client
    └── pages
        └── posts
            ├── index.html
            ├── index.js
            └── _index.scss


mgen controller <name> <actions> Creates controllers for Iron-Router, adds routes, creates pages for controllers. If only create, update, or destroy actions are passed, no pages are created. These are data only controllers. A namespace file is created if it doesn't exist which adds a db namespace for collections. This allows for a natural db.posts.find(...) synatax. Creating a posts controller adds a PostsController namespace. For example, PostsController.create() Possible actions: index, new, show, edit, create, update, and destroy. If no actions are passed, all will be created. See Example Controller - mgen controller posts --show generates the following:

├── both
│   ├── controllers
│   │   ├── _app.js
│   │   └── posts.js
│   ├── lib
│   │   └── namespaces.js   // adds a `db` namespace and `Posts` namespace
│   └── routes.js
└── client
    └── pages
        └── posts
            ├── show.html
            ├── show.js
            └── _show.scss
// show edit page for single Post : /posts/edit/:id
PostsController.Edit = AppController.extend({
  template: 'postsEdit',

  waitOn: function() {
    //return Meteor.subscribe('post',;

  data: function() {
    //return Post.findOne(;

  onBeforeAction: function() {
    console.log("  [PostsController.Edit]: loading", this.url);;

// controller to do something when complete
PostsController.create = function(data, callback) {
  console.log('Fired Create Post');

  // call Post model here...
  Post.create(data, function(err, id){
    if (callback) callback(err, id);
    if (err) return alert(err.reason);



mgen package <name> Creates a Meteor smart package. Flags for client/server/both coming soon.
mgen package mixpanel Generates the following:

└── packages
    └── mixpanel
        ├── both.js
        ├── client.js
        ├── package.js
        ├── server.js
        └── smart.json


Creates a Meteor collection in the both/lib/collections.js file. Collections are inserted into the db namespace, access them with db.posts.find(...) Passing in mgen collection posts generates the following:

db.posts = new Meteor.Collection('posts');


Coming Soon


Creates a publication on the server. Publications are stored in the server/publications directory inside of a script file file with the same name as the resource. Passing in
mgen publish post:userPost will generate a 'userPost' publication for the resource 'post'.

Meteor.publish('userPost', function() {
  // TODO index query
  // XXX bad performance no limit
  return db.posts.find({});


Coming Soon. Meteor Generate will create tests for Velocity for you by default.

Custom Templates / Config

Generators are only helpful if they save you time.

Soon, you will be able to define your own templates folder so that you can include things like form helpers, test helpers... anything you want. A project level mgen config file will help team members sync settings and reduce command line flags.

Example blog fire it up to see the general structure it generates. note this has extra logic added in