Search code examples
erlangcouchdberlang-otperl

How to add a plugin to CouchDB


I need to install plugin to CouchDB. The problem is that the only folder I can access on the server is user home directory. After I set ERL_LIBS env variable I can call my plugin module from erl console, but CouchDB returns '{"error":"unknown_error","reason":"undef"}'.

What is the right way to include external libraries on CouchDB start?


Solution

  • I managed to add an erlang module using the couchdb shell. Here is what I did:

    1. I started couchdb in interactive mode sudo couchdb -i
    2. Added the path to the beginning of the list with code:add_patha("/home/akshat/Desktop").
    3. Tested the list of paths with code:get_path().
    4. Found my path as the first item
    5. Compiled the module with c("/home/akshat/Desktop/test").
    6. Loaded the module with code:load_file(test).
    7. Called the module test:test()

    To test if the module is loaded by couchdb automatically on start you can restart couchdb and call a function within the module without performing the steps above. It should work as expected.

    This is the module I used for testing purposes

    -module(test).
    -export([test/0]).
    
    test()->
        hello.
    

    I think the problem with what you did could be that you did not add the module using the couchdb shell.