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.
- I installed Mongo on my local machine from http://www.mongo.org
- 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) - 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. - 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. - 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://
which you will need in the next step.: @dsXXXXXXX.mlab.com:PORT/DATABASENAME - 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.
- 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
- 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
- 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 - Almost there, folks. Inside the unpacked .tar directory (which will be called /bundle), enter the /bundle/programs/server/packages directory and run
npm install
- 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. - 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.
Awesome, I was just looking into hosting some meteor apps on my server at work. My question is: How do you update an app? I assume you’d change your local/development copy and then somehow get it up again on Webfaction? Just wondering how much of a hassle it is once you’ve got the first parts done.
You have the right idea. If I change the app locally, I have to go through steps 8 – 11 again on a SSH connection through the terminal. There’s actually one extra step in this case, which is using
ps -ef
to get the process ID which I subsequently kill before starting a new instance. I have the commands ready to paste in though, so it’s less than 5 minutes to go through those steps on another iteration of the application.