Pushing to a Hosting Service

Playing a Facebook game by yourself isn’t much fun, so to let other players use the game, you want to push to a hosting service. Luckily, Facebook makes it extremely simple to deploy your game to a hosted service.

To start, go to the Basic settings page of your Facebook Application, and click the Get One link in the Hosting URL line, as shown in Figure 20-6.

Figure 20-6: Setting a hosting URL.

c20f006.tif

Clicking this enables you to create an app on the Heroku hosting service. Click Next; then choose Node.js for the environment, and click Create. If you don’t have a Heroku hosting account, you need to follow the prompts to set one up.

To tell Heroku what to run, you need to create a file called Procfile that tells the platform what to run to start your web server. Create the Procfile file in your main game directory, and put the following single line into it:

web: node web.js

This tells Heroku to run the command node web.js to run your web server when it deploys.

To use Heroku, install the Heroku Toolbelt, which is a command-line interface that enables you to push your app to Heroku using Git (which is also installed with the toolbelt). To install the toolbelt, go to https://toolbelt.herokuapp.com/. Download the package appropriate for your platform (which should be preselected) and install it.

After you have the toolbelt installed, you need to log in to Heroku. ...

Get Professional HTML5 Mobile Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.