DEV Community

wolfiton
wolfiton

Posted on • Edited on

Absinthe Journey with Wolfiton or How to Bring the Absinthe Tutorial UP to Date- Part 2 Foundation

Series navigation
PART 1 Introduction
PART 2 Foundation
PART 3 The Walls
PART 4 The Door
PART 5 Testing
PART 6 Can you fly?
PART 7 The User

Hi everyone,

Welcome to part 2 of the series but before we jump in let's recap what we did in the first part:

  • We defined Absinthe
  • We set our objectives for the series
  • We built a TODO LIST
  • We separated the code logic

Now we are going to move forward and the first thing that we need is to install the requirements for our project.

If you are an advanced user and already know what you are doing skip ahead to Section 3 Let's Code.

Section 1

Requirements and installation

So let's start with the requirements:

  • OS: Linux, Mac, Windows with WSL or Virtual Linux
    (Virtual Box)

  • Optional: VsCode

  • Database: PostgreSQL My version: PostgreSQL 10

  • Programing languages(required): Erlang, Elixir. My versions: Erlang/23 OTP and Elixir 1.9.4

  • NodeJS above version 5, My version: NodeJS 12.4.0

  • inotify-tools(only for Linux Users)

  • Hex

  • Phoenix

To install them use the:

https://hexdocs.pm/phoenix/installation.html#content

My personal recommendation is to use asdf an extensible version manager that will work with a lot of languages, not just Erlang and Elixir. It can be found here https://github.com/asdf-vm/asdf.

Section 2

Verify Installation

On-wards we got to our application but first, let's verify that our environment is set up correctly. So in a Terminal(Konsole) type the following:

Verify Elixir Version using: elixir -v you should get the following output

▶ elixir -v
Erlang/OTP 23 [DEVELOPMENT] [erts-10.6.4] [source-7674e36d06] [64-bit] 

[smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.9.4 (compiled with Erlang/OTP 20)

Your Elixir version may differ from mine. But if you get similar output(Elixir 1.9.4 or any other version) then Elixir is good to go.

Verify PostgreSQL Version using: psql -V you should get the following output

▶ psql -V
psql (PostgreSQL) 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)

Your PostgreSQL version may differ from mine. But if you get similar output((PostgreSQL) 10.10 or any other version) then PostgreSQL is good to go.

Verify NodeJS Version using: node -v you should get the following output

▶ node -v
v12.4.0

Your NodeJS version may differ from mine. But if you get similar output(v12.4.0 or any other version) then NodeJS is good to go.

Verify Phoenix Version using: mix phx.new --version you should get the following output

▶ mix phx.new --version
Phoenix v1.4.11

Your Phoenix version may differ from mine. But if you get similar output(Phoenix v1.4.11 or any other version) then Phoenix is good to go. as long as the Phoenix version is 1.4 or above.

After all that we finished our verification and we are moving forward.

Section 3

Let's Code

Our application will be called 'WolfBlog', Dear Reader please feel free to name it however you like. But don't create the folder yet for our app.

We are going to let Phoenix generate everything for us.

Enough talk Let's Code!

Open a terminal and navigate to your desired location to store the code.

~Example~ Skip ahead Dear Reader, if you already know how to use the terminal.
As an example in Linux the code can be put like this:
First let's find where we are, type 'pwd'. The following output will appear.

pwd
/home/dan

So we are in the home directory, now we can make a folder called Codes like this to house all our codes.

Type: mkdir Codes

mkdir Codes

No response did it work?

We verify this using the following command ls -l | grep Codes

ls -l | grep Codes
drwxrwxr-x 2 dan dan  4096 feb 12 16:08 Codes

It worked!

OK,now we can store our WolfBlog app here.

To do that use: cd Codes

~Example end~

Now we are ready to Call The Power Of Phoenix

Type:

mix phx.new wolf_blog --no-html --no-webpack

Dear Reader, now you should get:

▶ mix phx.new wolf_blog --no-html --no-webpack
* creating wolf_blog/config/config.exs
* creating wolf_blog/config/dev.exs
* creating wolf_blog/config/prod.exs
* creating wolf_blog/config/prod.secret.exs
* creating wolf_blog/config/test.exs
* creating wolf_blog/lib/wolf_blog/application.ex
* creating wolf_blog/lib/wolf_blog.ex
* creating wolf_blog/lib/wolf_blog_web/channels/user_socket.ex
* creating wolf_blog/lib/wolf_blog_web/views/error_helpers.ex
* creating wolf_blog/lib/wolf_blog_web/views/error_view.ex
* creating wolf_blog/lib/wolf_blog_web/endpoint.ex
* creating wolf_blog/lib/wolf_blog_web/router.ex
* creating wolf_blog/lib/wolf_blog_web.ex
* creating wolf_blog/mix.exs
* creating wolf_blog/README.md
* creating wolf_blog/.formatter.exs
* creating wolf_blog/.gitignore
* creating wolf_blog/test/support/channel_case.ex
* creating wolf_blog/test/support/conn_case.ex
* creating wolf_blog/test/test_helper.exs
* creating wolf_blog/test/wolf_blog_web/views/error_view_test.exs
* creating wolf_blog/lib/wolf_blog_web/gettext.ex
* creating wolf_blog/priv/gettext/en/LC_MESSAGES/errors.po
* creating wolf_blog/priv/gettext/errors.pot
* creating wolf_blog/lib/wolf_blog/repo.ex
* creating wolf_blog/priv/repo/migrations/.formatter.exs
* creating wolf_blog/priv/repo/seeds.exs
* creating wolf_blog/test/support/data_case.ex

Fetch and install dependencies? [Yn] 

Type: y

Now we wait and let Phoenix do it's magic.

The output should look like this

* running mix deps.get

We are almost there! The following steps are missing:

    $ cd wolf_blog

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

Start your Phoenix app with:

    $ mix phx.server

You can also run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix phx.server

Which means Phoenix created our project successfully.

Congrats you generated your first Phoenix API Application.

How do you feel Dear Reader, was it hard?

Let me know in the comments below.

This ends Part 2 of our series.

Next time we are going to tackle the application in Part 3.

I know you wanted to really code, but we have to build a strong foundation before we build.

Also, things will get more advanced and we can easily lose our way.

I hope you enjoyed reading. See you next time in Part 3.

Credits:

https://hexdocs.pm/phoenix/installation.html#content
https://github.com/asdf-vm/asdf
My Linux Teacher
https://docs.microsoft.com/en-us/windows/wsl/install-win10

Top comments (0)