Deep-dive on the Next Gen Platform. Join the Webinar!

Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Working with Node.js
      • Node.js Behavior in Heroku
      • Troubleshooting Node.js Apps
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Working with AI
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Deployment
  • Preparing a Codebase for Heroku Deployment

Preparing a Codebase for Heroku Deployment

English — 日本語に切り替える

Last updated April 04, 2025

Table of Contents

  • 1. Track your codebase in a Git repository
  • 2. Add a Heroku Git remote
  • 3. Add a Procfile
  • 4. Listen on the correct port
  • 5. Use a database or object storage instead of writing to your local filesystem
  • 6. Complete language-specific setup
  • 7. Deploy your app
  • 8. Explore the Heroku platform

The Heroku platform provides great flexibility in your choice of programming language, application framework, and organization of code. There are, however, a few conventions that every Heroku app needs to follow.

If you have an existing codebase that you want to deploy to Heroku, make the following changes to help ensure that your first Heroku deployment is a successful one.

This article assumes that you have already created a Heroku account and installed the Heroku CLI.

1. Track your codebase in a Git repository

Heroku’s build system uses Git, the popular version control system. Consequently, your codebase needs to be committed to a Git repository in order to be deployed.

  • Git installation
  • First-time Git setup

If you are already using another version control system, consult its documentation for help exporting a snapshot to Git.

2. Add a Heroku Git remote

Every Heroku app has its own Heroku-hosted Git repo. You deploy new versions of your app by pushing your code changes to this repo. In order to do that, your local Git repo needs to know the URL of the Heroku-hosted repo.

Complete the step Creating a Heroku remote to add the Heroku-hosted repo as a Git remote.

Heroku Git is a convenience for deployment and not intended to be a stable git repository. Use GitHub (recommended), GitLab, BitBucket, or another version control system to track your codebase.

3. Add a Procfile

Commit a text file to your app’s root directory that is named Procfile without a file extension. This file tells Heroku which command(s) to run to start your app. These commands are probably the same as the ones you use to run your code on your local machine.

Here’s an example Procfile for a simple Node.js app:

web: node app.js

The web process type defined above tells Heroku to start up your web application by running node app.js. The web process type is special, because it’s the only process type that can receive HTTP traffic from the web (i.e., from your app’s users).

You can specify additional process types on separate lines in your Procfile, but process types besides web can’t receive web traffic. Process types can be any alphanumeric string (hyphens and underscores are also allowed).

For example (Rails):

web: bundle exec rails server -p $PORT
worker: bundle exec rake jobs:work

Consult language-specific guides for more information on creating a Procfile for your chosen language and framework.

Learn more about the Procfile

4. Listen on the correct port

On your local machine, your app’s web server can listen on any open, unreserved port. On Heroku, however, it must listen on a specific port.

This specific port is indicated by the PORT environment variable. When your web server starts up on Heroku, make sure it’s listening on the port number specified by PORT:

app.listen(process.env.PORT);

To avoid having to set the PORT environment variable when running on your local machine, you can replace the line above with the following:

let port = process.env.PORT;
if (port == null || port == "") {
  port = 8000;
}
app.listen(port);

In this case, the server will listen on port 8000 if the PORT environment variable isn’t set.

The examples above are for a simple Node.js app that uses Express. Consult your programming language’s documentation and Heroku’s language-specific guides for details on both reading environment variables and configuring your web server to listen on a particular port.

5. Use a database or object storage instead of writing to your local filesystem

If your app currently writes data to its local filesystem for persistent storage (including to a local SQLite database), on Heroku it must instead write that data to one of the following locations (depending on your use case):

  • A managed database service (such as Heroku Postgres)
  • A managed object storage service (such as Amazon S3)

This requirement exists because Heroku dynos (the Linux containers that run your code) have an ephemeral filesystem. Your app’s dynos are automatically replaced at least once daily (this is called dyno cycling), and each time they are, any data your app has written to the local filesystem is lost.

Initially, this “stateless” design pattern for web apps can seem surprising and confusing. Learn more about the methodology behind it.

Provisioning a database

Heroku Postgres is Heroku’s managed SQL database service, and it is the recommended relational database for Heroku apps. The affordable essential-0 plan provides a good starting place for smaller apps, and for testing out the Heroku platform.

Learn how to provision Heroku Postgres, and then also run Postgres on your local machine to ensure parity between your development and production environments.

If you don’t want to use Heroku Postgres, add-ons for other relational databases (including MySQL and MongoDB) are available in the Heroku Elements Marketplace.

Provisioning an object storage service

Learn about using Amazon S3 on Heroku.

Add-ons for managing an S3 bucket are also available in the Heroku Elements Marketplace.

6. Complete language-specific setup

The changes above apply to all Heroku apps, regardless of programming language. In addition to them, language-specific changes might be necessary for your codebase.

For details, see your language’s associated deployment article:

  • Node.js
  • Ruby
  • Ruby on Rails
  • Python
  • Java
  • Gradle
  • PHP
  • Go
  • Scala
  • Clojure

7. Deploy your app

At this point, your app is likely ready for basic deployment. See Deploying code to learn how to deploy.

8. Explore the Heroku platform

This article describes the bare minimum steps required to prepare a codebase for Heroku deployment. The Heroku platform provides many powerful features beyond simple app deployment, including:

  • Deployment via GitHub
  • Tools for continuous delivery and collaboration
  • Managed data services for Redis and Apache Kafka
  • Third-party add-ons for logging, monitoring, and more

Keep reading

  • Deployment

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices