Elixir and Phoenix

When I first started using Rails I remember the emotions I experienced. Excitement over how fast I could now build a web application. Amazement at the magic that simply did hard work for me seamlessly. I’ve since watched Rails grow into an amazing framework and is still my goto web framework.

For the past year or more I’ve been mainly using Node.js, and I have to say I like it. But I found myself wanting to try something new. Something that got me as excited about programming as Rails once had. After some searching I stumbled across Elixir and the Phoenix framework.

Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain.

If you are a Rails developer, you will immediately see some similarities. But don’t let this fool you that it is just the same framework. This is much like Rails, but without the object oriented language ruby.

Getting started is not hard at all. Let’s walk through how to get a basic ‘it’s working’ page. You will need both Erlang and Elixir installed to run Phoenix.

Let’s get our package manager installed, hex. This is much like bundler or npm.

mix local.hex

We also need PostgreSQL installed, so let’s make sure we have that

psql –version

Also very important, make sure you have node 5 or greater

node –version

Now let’s install Phoenix – our web framework

mix archive.install https://github.com/phoenixframework/archives/raw/ /master/phoenix_new.ez

We are now ready to create our first application. We will do a todo application.

mix phoenix.new todoapp

You will be prompted to install dependencies, say y to this.

Move into our new application and create the database.

cd todoapp

mix ecto.create

At the time of this writing, ecto has adaptors for the following databases:

  1. PostgreSQL
  2. MySQL
  3. MSSQL
  4. SQLite3
  5. MongoDB

Now let’s start the server!

mix phoenix.server

Our application should be running on http://localhost:4000