Search code examples
erlangerlang-otprebar

Where should you put application properties in a rebar erlang application?


A newbie question: I wrote my first rebar based erlang application. I want to configure some basic properites like server host etc. Where is the best place to put them and how should I load them into the app?


Solution

  • The next steps are to make a release and create a node in it. A node runs your application in a standalone Erlang VM. A good starting point for creating a release using rebar:

    Erlang Application Management with Rebar

    Once you have created a release. The configuration properties for all applications in your node can then be added to

    {your-app}/{release}/files/sys.config
    

    You can read individual properties as follows:

    Val = application:get_env(APP, KEY)
    

    Alternatively, all properties for your application can be read as

    Config = application:get_all_env(APP)
    

    In sys.config, properties can be added as a proplist.

    Example:

        {myapp,
          [
           {port, 1234},
           {pool_size, 5}
          ]
        }