Search code examples
erlangelixirnitrogen

Erlang Nitrogen web framework with elixir language


I am developing webapp using erlang nitrogen web framework, studying elixir. Is there a way i can code in elixir and use nitrogen web framework and existing developed code ?


Solution

  • It appears that the Nitrogen router assumes .erl files. I have not looked at the implementation details of the router. So, I'll assume that you will need Erlang wrappers for all the major modules. Additionally, Nitrogen uses Erlang records extensively. You can convert Erlang records to Elixir structs and back again, but that might be a hassle.

    You could implement some of the functionality in Elixir modules and call them from the Erlang code. You can also call the Erlang modules from Elixir pretty easily.

    For example:

    # Erlang to Elixir
    Elixir.MyModule.function(Var, atom, <<"Some char List">>).
    
    # Elixir to Erlang
    :module.function(String.to_charlist("some string"), :atom, var)
    

    Take a look at Elixir Record for handling Erlang records in Elixir.

    Keep in mind that you will need to convert string back and forth.

    If you want the main project to be a Elixir mix project, then create a src directory to put the Erlang source files in.

    I have a feeling it would all be more trouble than its worth. But you should be the judge of that.