How to Deploy Your Ionic Node.js app to Heroku

In this tutorial I will explain how to deploy one of my Ionic starters to Heroku with Dropbox. Both dropbox and heroku have a free tier that you can use. If you get serious about your app you can upgrade to heroku professional account which is similar to Amazon’s service but much easier to use.

Prerequisite: Sign up for dropbox.com and download their desktop client. Use one of my ionic starters with a node.js backend or use your own node project.

1. Create an account on Heroku.com

Screen Shot 2016-04-25 at 11.42.05 AM

2. Click on Create a new App on top right corner (+ icon)

Screen Shot 2016-04-25 at 10.08.04 AM

3. Choose your unique app name

Screen Shot 2016-04-25 at 10.08.31 AM

4. Connect your Heroku account to your dropbox account

Screen Shot 2016-04-25 at 10.08.55 AM

Screen Shot 2016-04-25 at 10.09.26 AM

5. Add JawsDB add-on (if you don’t want to host the DB yourself)

In your Heroku dashboard click on Resources tab and search for JawsDB in the Add-ons field.

Screen Shot 2016-04-25 at 10.13.06 AM

Screen Shot 2016-04-25 at 10.13.11 AM

Screen Shot 2016-04-25 at 10.13.17 AM

6. Click on JawsDB Mysql to see the setup information

In your Heroku dashboard click on the JawsDB add on, it will take you to your JawsDB settings page.

Screen Shot 2016-04-25 at 10.13.44 AM

In this case the database name is fiqf5mp2ngc6q3k0 you can see it after the port number in the connection url. The free version should work for most people, but you can look at their pricing page for more information.

7. In your Server/app.js enter the connection information matching the JawsDB config

Screen Shot 2016-04-25 at 10.23.36 AM

8. Copy the Node.js Server project files to your Dropbox Heroku folder

Heroku will create a folder in your dropbox/Apps/Heroku/{yourappname}/ In here you have to place all of the files and folders (Do not copy data and node_modules folders). Also you have to use the dropbox client and not the web-app (the browser copy won’t work) to copy the project.

Screen Shot 2016-04-25 at 10.50.24 AM

9. Deploy your node.js project within Heroku

Click on the deploy button once you’ve uploaded the files to dropbox.

Screen Shot 2016-04-25 at 10.38.18 AM

10. Test your app deployment by going to your app heroku web url

Screen Shot 2016-04-25 at 10.39.14 AM

In my case it was https://ionicsociallogin.herokuapp.com

11. Replace localhost references in your Ionic Frontend App

You have to point all the service calls to your new web app url. To do that, you have to replace http://localhost:3000 with your new web-app url, in my case it was https://ionicsociallogin.herokuapp.com in Frontend/www/js/services.js.

Screen Shot 2016-04-25 at 10.53.19 AM

12. Run your Ionic app

Go to your Frontend folder and run ionic emulate ios to start your iPhone app.

Web App Solution

If you are making a web app for the browser and not running as a native app, then you have to move the angular portion of the code into the server part.

Copy the /www folder from your frontend into the server /public folder. Then republish to Heroku. You can then access your UI from http://yourapp.herokuapp.com.

screen-shot-2016-10-09-at-9-08-41-pm

Good luck!