16
votes

Were would you put code which you want to run only when your application/api starts in vanilla Phoenix application? Let's say I want to make sure some mnesia tables are created or configure my logger backend. The other thing is runtime configuration. They mention it in documentation but it's not clear to me where one would define/change runtime configuration.

Endpoint.ex seems like a place where initial configuration is done but by looking at docs I can't find any callback that would allow me to run code only once at startup.

1

1 Answers

21
votes

Put it in the application callback module. It is usually the name of your application: lib/my_app/my_app.ex in the start/2 function. The 2nd line of the module should have use Application.