Time Estimate


Prepare the App for Local Development


This section of the quick start requires the following to be installed on your local machine:

When an app is deployed to Heroku, it keeps a copy of it in a git repository to facilitate sharing. In a production environment, you typically store your code in a company git repository or use a service like GitHub. In this step, you are instead cloning the source from Heroku, making a few changes, and then deploying the code back.

You can use a git command line or GUI client, but your machine needs to be authenticated to Heroku. To log in from the command line using the Heroku Toolbelt, run:

heroku login

When you've logged in, you can use the command line to clone an app's git repository to your local machine. In the following, replace <APP_NAME> with your app's name:

git clone https://github.com/jamesward/heroku-connect-phone-change <APP_NAME>

A directory containing the source for your app is created with the same name as your <APP_NAME>. Change to this new directory and add a remote git connection to your heroku app. This allows you to easily push your modified code back to your heroku app:

heroku git:remote -a <APP_NAME>    

Run the App Locally

To run your app locally, ensure that you have Node and npm installed from the requirements above. The Node.js application that you deployed, and which you now have on your local machine, first needs its dependencies fetched. To do that, run:

npm update

To run your app locally, you need a Postgres database that the app connects to. Normally, you set up a local database containing some demo data and use that. However, you can also point straight to the Heroku Postgres database that you provisioned earlier by setting the DATABASE_URL environment variable.

To set the DATABASE_URL environment variable to the Heroku Postgres database and start the local Node.js app, run the following from the command line:

DATABASE_URL=`heroku config:get DATABASE_URL` PGSSLMODE=require npm start

If you are using a Windows machine this needs to be broken into 3 separate commands:

npm start    

You can now access the local application by opening up a browser and navigate to http://localhost:5000.