Logo
ManuelSchoebel

Private remote Meteor.js packages hosting on your own server

With meteorite you can add packages to your app in a very easy way by just typing:

mrt add PACKAGE_NAME

The package you add to your app this way are public packages on athmosphere. I am developing a lot of different packages but mostly they are packages that include some small helpers or reflect my personal coding style and are not ment for the public. Also if you create a public package this will also only help other people if you are willing to maintain them, too. Because of this and other reasons I do not make any package publicly available but of course I want an easy way to add those to my apps, too!

I also want to access my packages online because I am not only developing on my local machine but on a laptop, too. And especially if you are working with other people you need to make your packages accessible. Things like version control or different versions of a package should be possible and thats why I use git.

For my git repositories I use a really low end virtual server for about 10$ a month. I also use this small machine for development versions of different apps, e.g. for testing and to show the current versions to clients, too. If you do not need that you can also simply use bitbucket as Mike Conneen mentioned in the comments below.

##Setup the server Basically you need to do two things. The first one is to install git and the next one is to log in your server without a password via ssh using a private and public key.

Installing git is easy and e.g. on a unbuntu system done via:

sudo apt-get install -y git

Installing git

Now that git is installed you want to access the server with your ssh key. If you do not have a ssh key, you can create one like this:

mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen –t rsa

Now you need to copy your newly created public key to your webserver and the easiest way is to do it with ssh-copy-id:

ssh-copy-id –i YOUR_PUBLIC_KEY USERNAME@HOST

If you do not have ssh-copy-id, simply copy it from your linux server (if you are working on a mac).

Great now you should be able to log in your server without entering any password with

ssh username@server

##Create a Git repository for a Meteor.js package Now that we have our server ready we can create a git repository for our Meteor.js package on the server.

cd /var/git/meteor_packages/    // path where you want to store your packages
mkdir ms-seo   // name of the meteor package
cd ms-seo
git init --bare   // initialize your git repository

That creates a 'bare' git repository and means that this git repository does not have a working tree. This bare git repository does not contain the actual files of your Meteor.js package but only the version control information. And this is all you need in order to push and pull your local git repository to the remote one on your server. And this is also all you need to make it work with meteorite as we will see next.

##Creating your local Meteor.js package When I create a new Meteor.js package I start with the bare git repository and then clone the empty git repo.

cd ~/Workspace/priv/meteor_packages   // path to your local packages
git clone username@yourmachine:/var/git/meteor_packages/ms-seo

Now you have your local meteor package and you can start to develop it. Once you have a working version you can push it to your bare git repository again.

// where origin is the name of your remote server
// and master is the name of the git branch
git push origin master

Finally we can use our meteor.js package in any app on any machine from that we have access to our remote server.

##Adding a private Meteor.js package to an app This is a really simple step, you have to add your remote package to your smart.json file from meteorite:

// smart.json
{
    "packages": {
        "ms-seo": {
            "git": "ssh://USERNAME@YOUR_SERVER/var/git/meteor_packages/ms-seo",
            "branch": "master" // this is optional
        }
    }
}

Also add the package to the packages file in your .meteor folder

// YOURAPP/.meteor/packages
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

ms-seo

Now you can (re)start your app with

cd into/your/app
mrt

Meteorite loads the remote package and builds it. That is all there is to do for your own remote private meteor.js packages.

##Private local only packages In your smart.json you can also specify a meteor.js package on your filesystem if you want to. For our newly created ms-seo package we could also add it this way in our smart.json file:

// smart.json
{
    "packages": {
        "ms-seo": {
            "path": "PATH_TO_PACKAGES/ms-seo"
        }
    }
}

If you only work on one machine but you have multiple apps, this might be easier to start with. Do not forget to add the package to your .meteor/packages file, too.

###Links Git cheat sheet
Git website
Passwordless ssh
Atmosphere

©️ 2024 Digitale Kumpel GmbH. All rights reserved.