title: Using the Erlang client library from Riak in Nitrogen
body: <p>This question is a continuation of <a href="https://stackoverflow.com/questions/4222478/including-the-erlang-client-library-from-riak-in-nitrogen">Including the Erlang client lib</a> which was asked before.</p>
  
  <p>I was able to include the library by changing:</p>
  
  <pre><code>{mimetypes,     ".*",   {git, "git://github.com/spawngrid/mimetypes",   {branch, master}}},
  
  %% Uncomment the following lines and comment the bottom lines with specific
  %% tags to always pull the latest versions
  {nitrogen_core, ".*",   {git, "git://github.com/nitrogen/nitrogen_core",{branch, master}}},
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>{mimetypes,     ".*",   {git, "git://github.com/spawngrid/mimetypes",   {branch, master}}},
  
  {riakc, "1.4.1",
            {git, "git://github.com/basho/riak-erlang-client", 
                         {tag, "1.4.1"}}},
  
  
  %% Uncomment the following lines and comment the bottom lines with specific
  %% tags to always pull the latest versions
  {nitrogen_core, ".*",   {git, "git://github.com/nitrogen/nitrogen_core",{branch, master}}},
  </code></pre>
  
  <p>in <code>rel/nitrogen/rebar.config</code> and recompiling with make</p>
  
  <p>Now that I have those installed under the <code>lib</code> folder, I'm not sure where I should be implementing the <code>riakc_pb_socket</code> lib as <a href="http://basho.github.io/riak-erlang-client/" rel="nofollow noreferrer">suggested in the docs</a></p>
  
  <p>I've tried putting </p>
  
  <pre><code>{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),
  </code></pre>
  
  <p>into <code>nitrogen_sup:init()</code> but i get this error message:</p>
  
  <pre><code>application: nitrogen
  exited: {{{badmatch,{error,{tcp,econnrefused}}},
            [{nitrogen_sup,init,1,
                           [{file,"/home/neil/proj/nitrogen/rel/nitrogen/site/src/nitrogen_sup.erl"},
                            {line,43}]},
             {supervisor,init,1,[{file,"supervisor.erl"},{line,239}]},
             {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
             {proc_lib,init_p_do_apply,3,
                       [{file,"proc_lib.erl"},{line,239}]}]},
           {nitrogen_app,start,[normal,[]]}}
  type: temporary
  </code></pre>
  
  <p>Am I supposed to make this connection to riak database once during the app initialization, or often as new requests are handled. I saw some talk of connection pools, would this be something that I setup once during app initialization, then link to with new processes.</p>
  
  <p>I'm new to erlang/OTP and this framework, so any direction will be greatly appreciated.</p>
  
  <p><em>added:</em></p>
  
  <p>When I run the nitrogen app via <code>bin/nitrogen console</code>, I am able to run <code>{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1",8087).</code> and I do manage to get a <code>pong</code> back from <code>riakc_pb_socket:ping(Pid).</code></p>
  
  <p>I guess the question now is: In which files does one generally setup/manage riak connections with respect to queries/reads/writes?</p>