Tag Archives: shell

Hosting Meteor JS Applications - My Process on Webfaction

There has been some interest expressed here and on Twitter for a description of the process of moving an application from the free meteor.com to my own server. I run my web applications (such as this blog) on Webfaction, which gives a lot of flexibility for setting up a number of different hosted services. I won't say each step below is easy and as straightforward as it sounds, so feel free to add your difficulties to the comments below, and I'll elaborate. Having the steps in one place will hopefully be as useful for you as it likely will be for me.

Note: Steps 1 - 3 in the list below are just for downloading data you may have collected in an online application onto your computer. If you don't care about the online data, you can skip down to step 4.

  1. I installed Mongo on my local machine from http://www.mongo.org
  2. In a terminal on my local machine, I entered meteor mongo --url my-app.meteor.com to get the username, password, url, port, and database name from the *.meteor.com website. The result is a URL that contains the information you will need for the next step: (username:password@url:port/databasename)
  3. save the data onto my local computer using mongodump --host hostname:port --db databasename -u username -p password -o ~/Desktop where the information from the last step replaces the username, password, etc.
  4. To create a packaged version of the app that runs on my computer, go to the Meteor project directory, and type meteor build --architecture os.linux.x86_64 ./ . This assumes that the server that will be running your project is a Linux machine...but this assumption is probably a good one for most hosting services.
  5. Create a free account on mLab (http://www.mlab.com). The free account gives you 500 MB of space for databases. For comparison, the total size of my most-used application is only 2.7 MB. I think you'll have enough space. The important thing to get, once you have a database set up, is called the URI. If you create a database, there is a box at the top of the page that gives you information that looks like this: mongodb://:@dsXXXXXXX.mlab.com:PORT/DATABASENAME which you will need in the next step.
  6. I learned the Webfaction specific steps from reading this page, though you won't need to do the Mongo steps if you are using mLab as I am. On the Webfaction server, you must install node. You can do this by following the steps here. You must also create a custom WebSockets application. This will give you a port number that you will need in the step below where local variables are set.
  7. Again, this is a Webfaction specific instruction, but you need to attach the application to a domain/URL where your application will be accessed. Save this URL
  8. Once you have created the WebSockets app, upload the .tar file (from step 4) to the /webapps/web-sockets-application directory through ftp and unpack with tar -xzf my-app.tar.gz
  9. Using the mLab information from step 5, the port number from step 6, and the location of the node application from step 6, you'll need to fill in the appropriate parts of the commands below:

    export MONGO_URL="mongodb://:@dsXXXXXXX.mlab.com:PORT/DATABASENAME?autoReconnect=true" # 2
    export MAIL_URL='email-address-for-sending-mail-from-your-app'
    export PORT="PORT-NUMBER-FROM-STEP-6"
    export ROOT_URL="DOMAIN-FOR-APPLICATION-FROM-STEP-7"
    export PATH=~/webapps/node/bin/:$PATH

  10. Almost there, folks. Inside the unpacked .tar directory (which will be called /bundle), enter the /bundle/programs/server/packages directory and run npm install
  11. Go back to the /bundle directory and run nohup node main.js . This terminal command will run a command continuously on the shell, even if you close the terminal.
  12. If you've made it this far, you might just have your Meteor app running on your own server.

I hope this helps you, but if you run into trouble, throw a comment below and I'll see if I can help.