elixirian · elixir · recipes · iex

Elixiran | Recipes | Recipe 1: .iex.exs file

IEx—the Elixir Interactive Shell—is your forge, your friend, your debugger, your playground.

It’s where code feels alive.


🍳 Recipe 1: Start Smart with .iex.exs

Drop a .iex.exs file in the root of your Elixir project - it automatically runs every time you launch IEx.

Create 2 files:

# file: .iex.exs

IO.puts("Loading iex_helpers.ex...")
Code.require_file("./iex_helpers.ex")

IExHelpers.greet()
# file: iex_helpers.ex

defmodule IExHelpers do
  @moduledoc """
  Helpful methods to use in IEx
  """

  @doc """
  Prints welcome message
  """
  def greet(), do: IO.puts("Welcome to IEx!!!")

  @doc """
  Returns all files in current dir
  """
  def list_files(), do: File.ls!(".")
end

Run iex in terminal:

$ iex

Erlang/OTP 27 [erts-15.2.6] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.18.3) - press Ctrl+C to exit (type h() ENTER for help)
Loading iex_helpers.ex...
Welcome to IEx!!!
iex(1)>

Result must be as in screenshot:

recipe 1