Preparing your App - Adding a Procfile

A Procfile tells Heroku how to startup your application on it’s servers.

A Procfile is a mechanism for declaring what commands are run by your application’s dynos (or a web process) on the Heroku platform. You can use a Procfile to declare various process types, such as

  • a web dyno to run your web application
  • workers that run in the background and can deliver emails later without holding up the webserver’s code
  • scheduled tasks like sending notifications or SMS messages every morning at 9am
  • other processes like links to Twitter streaming API to collect data for your application

Procfile naming and location

A Procfile is a file named Procfile. It should be named Procfile exactly, and not anything else. For example, Procfile.txt is not going to work. The file should be a simple text file.

The file must be placed in the root directory of your application. It will not function if placed in a subdirectory.

Adding your Procfile

Using your favorite text editor open the project folder and add a new file called ‘Procfile’ (a text file) in the root directory of your application. We’ll use this to explicitly declare what command should be executed to start your app on Heroku

Open this file and edit the contents to read

web: bundle exec ruby app.rb -p $PORT

Tip If your main code file isn’t named app.rb change it accordingly!

This declares a single process type, web, and the command needed to run it. The name web is important here. It declares that this process type will be attached to the HTTP routing stack of Heroku, and receive web traffic when deployed. The command used here is to run the web server.

Procfiles can contain additional process types. For example, you might declare one for a background worker process that processes items off of a queue.

One more thing

Don’t forget to commit your changes

  • Open Github Desktop, commit and sync your changes.

Full credit: Much of this is adapted from the Heroku guide, but set up to show you how to transition a local project into a heroku deployable project.

×

Subscribe

The latest tutorials sent straight to your inbox.