Getting your development environment running
erlang_js is the first order of
business. I’ve done all of my testing on a Mac OS X system, both Lion (10.7)
and Mavericks (10.9). I use Erlang
R14B04 for these tests, since that
version is what we primarily target at the office.
If you want to manage multiple versions of Erlang on your OS X system, I highly recommend the erlbrew utility as a quick and easy way to maintain multiple versions. We’ve recently made it support R14 builds on OS X Mavericks, so there’s no excuse not to use it!
Assuming you have a working Erlang and OS X command-line development tools
active, execute the following to checkout the
erlang_js project and build it
git clone git://github.com/basho/erlang_js.git cd erlang_js make all test
As an example, let’s imagine a deeply nested data structure that represents a
that data to find the first active network interface. Here’s an example of how
you’d do it using
The real trick is building your Erlang data structure properly so that the
custom version of
mochijson2 can encode the object as JSON. As you see from
the examples, use tuples with a
struct atom as the first member to specify
an object. Arrays are just arrays.
I have noticed that it is very easy to confuse a single instance of the
js_driver object and it is hosed until a new one is created, so consider
that in how you structure your driver usage.