I created a mochiweb instance
src/
|-- Makefile
|-- room.erl
|-- myserver.app
|-- myserver.erl
|-- myserver_app.erl
|-- myserver_deps.erl
|-- myserver_sup.erl
|-- myserver_web.erl
`-- uuid.erl
in myserver_web.erl
I am able to access the application config
{ok, "0.0.1"} = application:get_key(vsn),
However in room.erl
, I am not able to access the application config (specifically the env
list).
undefined = application:get_key(vsn),
The supervisor does not start the room, nor do I want it too.
I'm new to OTP and I realize I'm probably doing something stupid, but I would really appreciate anyone's help.
Cheers!
Use
get_key(myserver, vsn)
instead. Note that the application needs to be loaded first.I figured it out... The answer is quite stupid and I feel silly posting, but I hope someone else can benefit from me.
I was actually doing everything right (as are all the other answers), but I was using mochiweb's auto reloader and not actually stopping the server. Once I did that everything was fine.
DOH! Sorry!
From the Erlang documentation about the application:get_key/1-2 function:
What's the application of my_server_web.erl? What's the application of room.erl?
Is the key specified? Is the application loaded?
Regarding the "env" key, you can use the application:get_env/1 function instead.