3

I am a greenhorn in elixir and want to test the Poison functions from iex

https://hexdocs.pm/poison/1.3.1/#functions_details

iex> Poison.decode("[1,2,3]")

When I run this command I am getting the error below.

iex(1)> Poison.decode("[1,2,3]")
** (UndefinedFunctionError) function Poison.decode/1 is undefined (module Poison is not available)
    Poison.decode("[1,2,3]")

What am I doing wrong here?

Paweł Obrok
  • 22,568
  • 8
  • 74
  • 70
veer7
  • 20,074
  • 9
  • 46
  • 74

2 Answers2

3

If you just start iex it has no extra code loaded. Assuming poison is added as a dependency in your mix.exs you can start iex in the context of your application by running:

iex -S mix

You can also do:

iex -S mix run --no-start

In this case it will only load the code, but not start your supervision tree.

Paweł Obrok
  • 22,568
  • 8
  • 74
  • 70
2

If you have a mix project (created by mix new project_name or mix phx.new project_name), run iex -S mix to load dependencies into your iex console. Make sure you are in the projects directory. If you don't have such project, create it.

Make sure the required packages are listed in mix.exs:

defp deps do
  [
     {:poison, "~> 4.0"}
  ]
end
Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
denis.peplin
  • 9,585
  • 3
  • 48
  • 55