Getting Started with Clojure on Heroku

Last week I introduced the Den of Clojure to Heroku. I really enjoyed learning more about Clojure and experiencing super simple Clojure deployment on Heroku. For those who haven’t yet deployed Clojure on Heroku, lets walk through 8 quick steps to get you started:

  1. Install the Heroku Toolbelt and Leiningen
  2. Login to Heroku from the command line: ```bash heroku login
    
    If this is your first time logging into Heroku from the command line then you will be led through some steps to associate an SSH key with your Heroku account.</li> 
    
      * Create a new Leiningen build definition by creating a file named **project.clj** containing: ```clojure
(defproject hello-clojure-noir "0.1.0-SNAPSHOT"
  :main web
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [noir "1.2.1"]])
    As you can see from the dependencies, this simple app uses the [Noir web framework][4].</li> 
    
      * Create a simple Noir app by creating a file named **src/web.clj** containing: ```clojure

(ns web (:use noir.core) (:require [noir.server :as server]))

(defpage “/” [] “hello, world”)

(server/start (Integer/parseInt (or (System/getenv “PORT”) “8080”)))

            
            This very basic web app returns "hello, world" for requests to "/". It starts the server using either the port defined by an environment variable named "PORT" or a default of 8080.</li> 
            
              * Test this app locally by running: ```bash
lein run
            Then visit <http://localhost:8080> in your browser and verify that you see "hello, world".</li> 
            
              * To upload this application to Heroku you will first need to create a Git repository, add the files to it, and commit them: ```bash

git init git add project.clj src git commit -m init

                
                  * Now create a new application on Heroku: ```bash
heroku create
                This creates an HTTP and a Git endpoint for your application. The Git endpoint will be added to your Git configuration as a "remote" named "heroku". </li> 
                
                  * Upload your Git repository to the Git repository for your application on Heroku: ```bash

git push heroku master

                        
                        This will kick off the Leiningen build process on Heroku. The build will download the dependencies for the app then compile the app and put everything into a "slug" that will be deployed onto a [Dyno][5]. Once the process is complete you can open the HTTP endpoint for your app in your browser:
                        
                        ```bash
heroku open
                    You should now see "hello, world" coming from the Cloud!</li> </ol> 
                    
                    The source for [this example is on GitHub][6].
                    
                    To learn more about Clojure on Heroku, check out [the Heroku Dev Center][7]. Let me know how it goes!