Erlang, Nitrogen and automatic rebuild.
I came across Nitrogen about a year ago and loved it and it has come on very well since then.
Finally I have been presented with an opportunity to use it for a freelance project (currently under an NDA) and the first thing that kind of caused me a little upset was the fact that unlike PHP for example, it didn’t seem to automatically rebuild and reload any modules that you have edited.
It is possible that I missed something in the documentation but I am pretty sure I didn’t too… however, I remember there being a single point of entry that all requests go through… the perfect spot to use the Erlang make module.
And here is my solution. All you do is modify your existing YOURAPP_app.erl file like this :-
request(Module) -> io:fwrite("request-pinchpoint: ~w~n",[Module]), make:all([all,load,debug_info]), nitrogen:request(Module).
Once you have done that, rebuild it from the command line for the final time (yes!) and then run it again…
$ make erl -make $ ./start.sh Starting Nitrogen. Erlang R13B04 (erts-5.7.5) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.7.5 (abort with ^G) (nitrogen@localhost)1> --- Nitrogen is now running on inets. Serving files from: ./wwwroot Template root is at: ./ Open your browser to: http://localhost:8000 ---
Now go and edit a module file beneath the src/ tree and then refresh the page… here is what you should see if for example you modifed the default home page module in web_index.erl…
request-pinchpoint: web_index Recompile: ./src/pages/web_index
That’s it. Happy hacking.
PS: You can remove the pinch-point print statement if it annoys you too much, I just like to see / know what’s going on sometimes!
3 comments to “Erlang, Nitrogen and automatic rebuild.”
June 28th, 2010 at 7:37 pm
You save my life!
really this behavior of nitrogen is very annoying!
August 18th, 2010 at 2:33 am
I used to have a monitoring process keep checking file system for any change (I got it from yaws?)
August 18th, 2010 at 9:11 am
You might be interested in this:
http://www.trapexit.org/forum/viewtopic.php?p=29441&highlight=#29441
I wrote it a long time ago, when I first started playing with erlang and yaws, and also this,
http://www.trapexit.org/forum/viewtopic.php?p=37402&highlight=#37402
I am getting into haskell these days! We love it don’t we!