Couple of tips for developing Elixir apps using Plug


#1

Being a huge C9 fan, once I decided to start learning Elixir this week the first question I asked myself was: Can I use C9? Well, of course you can! Here are a couple quick tips i learned along the way. Hopefully it’ll help anyone else who heads down this path:

  1. Daniel Berkompas has a great post on installing Elixir on a C9 instance here: http://blog.danielberkompas.com/elixir/2015/08/28/how-to-run-elixir-cloud9-ide.html

  2. For mix based apps, you can configure the Run and Preview buttons by setting the Run Command to iex -S mix, setting the CWD to the root folder of the mix app to test, and setting ENV to {dev, test, prod}

  3. If you are building a Plug app, it will by default serve on port 4000. This one kept me scratching my head for a while but finally figured out the correct configuration point. In your Supervisor.ex file use the following code in run:

{port, _} = Integer.parse(System.get_env("PORT"))
opts = [port: port]
    
{:ok, _} = Plug.Adapters.Cowboy.http PlugWorld.Router, [], opts

This will force cowboy (the underlying HTTP engine) to run on the port provided by C9 and not 4000.

Any other tips hit me up! Elixir seems like an awesome language and I’m having fun with it.

Don


Writing an Elixir App