Photo by Markus Spiske on Unsplash

The .iex.exs file

Ria Cataquian
Aug 23, 2017 · 2 min read

Without further ado, ladies and gents, meet .iex.exs.

What is it?

It is a file you’ll create at the root of your Elixir project, name as is: .iex.exs, and declare to it variables, aliases, imports and anything else just like you would do on an IEx, Elixir’s REPL or in a module. When you fire up your IEx, you’ll have access to whatever it is you declared in your .iex.exs, be it a variable, alias or import.

What happens if you call a variable/function that is not declared?

An instance of Phoenix server, run iex -S mix phoenix.server

Two things to notice in our example. First, the shell raised an error as we try to access a non-existent variable or function, as expected. Second, calling out Repo did not raise an error. However, it also didn’t suggests you functions under that module which it will normally do (when you press the tab key after the dot), simply because it doesn’t point out to our Phoenix app’s Repo module.

Let’s fix it. First, create your .iex.exs at the root of your Elixir project:

some_string = “This is something I declared in my .iex.exs"some_map = %{
"name" => "Map",
"description" => "I'm the map, I'm the map, I'm the map!"
}
alias Blog.Repo

Then let’s restart our IEx and try it out again.

some_string, some_map and Repo are now all accessible in our IEx instance. Of course, there are countless ways to make it useful. Use it to alias commonly used modules so you won’t have to repeatedly alias it whenever you fire up or restart your IEx or maybe declare variables you’ll be using as you test out your Elixir functions or import functions from modules and so on.

Know more about it from Elixir’s official documentation.


Thank you for reading. As always, happy coding!

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade