Deploying to Heroku

A server app isn't very useful without a server.

Luckily, Heroku provides free plans for limited use and is super easy to deploy to. At the moment, they allow 550 (plus an additional 450 if you verify your account with a credit card) dyno hours distributed between all of your servers, with machines down cycling when they aren't active. In effect, this means that your server generally won't ever run out of uptime hours, provided it isn't being hit with traffic constantly.

Start by creating an account at http://www.heroku.com and install the Heroku Toolbelt from
http://toolbelt.heroku.com. Once you've done so, go to the root of your project folder and type the following:

$ heroku create

This will create a new Git remote and set up your app at a random URL like
https://calm-dusk-16214.herokuapp.com/.

Next, create a new file named Procfile. Heroku looks at this when you deploy to know how to run your app (otherwise it defaults to node start, but we use that to launch our Webpack development server in this book instead). Add the following contents:

web: node build/server.js 

Save it and then make sure that you have the latest bundle built:

    $ npm run server

Press ctrl+c after it builds; we don't need to run it any more.

Lastly, add everything to a commit:

    $ git add . && git commit -am "Time for Heroku"

We're now going to deploy. Assuming that you're working from the master branch, type the following:

    $ git push heroku master
Heroku always deploys from the master branch. If you've checked out the chapter8 branch in Git, type the following instead:
$ git push heroku chapter8:master

Visit the URL provided by heroku create -- you should see your app in all its glory, online and accessible to anyone on the Internet. Congratulations! You've just written a pretty awesome webapp.

Didn't think you'd get a crash course on writing backend code in a book about data visualization, did you?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset