Live Blogging: getting started with Erlang and Nitrogen

Note

This is an experiment where I try "live blogging": I blog as I get along further in the process... Feel free to comment/tweet during the process...

 

Introduction

As I had yet another idea for a startup, I fired up Visual Studio and started implementing a small demo...

However, the main feature that would elevate my example requires a lot of interaction, and quite frankly, interaction is a pain in web apps IMO, as there is still a mental shift between frontend and backend. For this particular thing I needed the distance to be as small as possible, so I started searching and found Erlang...

I will not go into the details why this looks like a perfect match, because I would like to build an MVP first, but I can tell you that it resembles the bee's knees at this current moment to me... So how do I get started? This is a walkthrough where I will post my progress... This post will evolve as I manage to get further....

Installation

Well, I still work on windows, so I downloaded the binary erlang package from here: https://www.erlang-solutions.com/downloads/download-erlang-otp

I downloaded the win x64 binary and ran it, as simple as that; mission #1 accomplished; a few more to go.

The web framework

Well, I decided to go for nitrogen, as it looks pretty neat IMO, so I created a nitrogen folder and downloaded the windows package from https://nitrogenproject.com/downloads and unzipped it.

#2 accomplished

Hello world

I copied the whole nitrogen package to a new folder called HelloWorld - how original - opened a cmd window in the folder, and this is what I typed and the result..

So I opened up Windows explorer and checked... Aha!

 

I copied the bin path, went back to my hello-world folder, right-clicked start.cmd and chose for edit, and assumed replacing 5.7.5 (the Erlang version in the nitrogen package) with 5.9.2 would be enough, but then I noticed: there is also and erts-5.7.5 subfolderfolder in the hello world project, which looks like it contains the whole erlang version...

So I decided to look a bit closer...

When running the commands from the batch file manually with the installed erlang  (i.e. the one from c:\program files) I get a crash on the execution of the last line, so it compiles, but refuses to run. So I decide to uninstall erlang, as I assume it is some kind of a version conflict, and I probably do not need the installation anyway.

So I removed the installed Erlang, and also found out I had another (32-bit) version installed, so I removed that one as well...

However, when I try to compile using the following statement I still get an error:

 

C:\blah\nitrogen\helloworld>"erts-5.7.5\bin\erl.exe" -pa %PA% -make
Could not load module C:\Program Files\erl5.7.5\erts-5.7.5\bin\erlexec.dll.

So I decided to go looking for erlang 5.7.5 for windows.... But then it hit me; google to the rescue: https://groups.google.com/forum/?fromgroups=#!topic/nitrogenweb/0vXvXwLvBOM

So I should probably reinstall the Erlang binaries I first installed and try to build nitrogen myself...

Let's try again....

Ok, installed the initial erlang version again (had to kill an apparently still running erlang proces).

Now I went looking into a nitrogen tutorial (https://nitrogenproject.com/doc/tutorial.html) and pulled in the nitrogen source code from github.

I browsed a bit further in the git project, and found this document mentioned on the readme: "Compiling Nitrogen on Windows"... There they advise to install Erlang for win R15B02 for windows and install it in the folder "c:\erl5.9", so I installed yet another erlang (5.9.2), but now in the recommended folder, and tried running nitrogen again; here's what happened:

As it still does not work, I assume it is time to try and compile the thing...

So I add c:\erl5.9\bin to the path in my environment settings.

Now I install msysgit using the netinstaller, not the regular one, and install into the default c:\msysgit

You need to use this version, as this downloads the source for git and enables you with a complete mingw build environment, which allows you to build the nitrogen source code as well...

Building git apparently seems to take a few minutes...

... And some more...

And we're finally there!!! 

Now time to clean up the folders and pull in the sourcecode and build it...

 

And we fail again... 

So I am now digging into the rebar mailing lists: https://lists.basho.com/pipermail/rebar_lists.basho.com/2011-September/001074.html

 

Aha, found it; I simply have to make sure c:\msysgit\bin is contained in the PATH environment variable; it now fetches all dependencies....

Crap... Now I get a compile error in nitrogen itself...

 

So I checked to see if there was any Erlang feedback available on twitter...

In the mean time I'll start looking at the source over at github; maybe I have a stable branch or similar...

 

Aha, I found an open issue regarding the mimetypes library on github, but apparently there's not a lot of response there.... https://github.com/spawngrid/mimetypes/issues/10

Currently in the process of digging in the source code of the mimetypes lib, and I also received a good tip from Neil:

Ok; I took a small break; looks like the problem is actually in the post_compile script for the mimetypes; currently debugging erlang script!!! 

My understanding of erlang is growing slowly Cool... Looks like this file just extracts all method definitions, since these have not changed, there is no need to change it, so I just commented the whole enchilada (gist here: https://gist.github.com/3714046) et voila, it compiles!

 

 

AAAAAAAAAAAAAAAAAAAAARGH ! 

Still no go; I'll call it a day for today, as I have some other stuff to do as well, and this took way longer then I hoped.... Laters!

I'm back

... with a vengeance, I hope...

A new day, new ideas, so I started looking at the google groups, and apparently I'm not the first one having this problem: https://groups.google.com/d/msg/nitrogenweb/KoBJCXr5SEI/UhgkWWTp09wJ .

So let us try that....

Uninstalled all erlang..

Removed original folder

Now downloading and installing windows release from https://www.erlang.org/download_release/6 in "C:\Program Files\erl5.7.5", not the (x86) folder.

Double click start.cmd in the nitrogen folder, it should open up the erlang console. surf to https://localhost:8000 et voila !!! FINALLY !!!

 

Finally

I wrote a small follow-up post.