Prepare the App for Local Development

Prerequisites

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:

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:

cd <APP_NAME>
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: