By @gumm
Web development has never been more challenging. The Internet is intensely competitive and treacherous. Site malfunction and downtime are unacceptable. Clients demand ever more features with ever tighter deadlines. Popular sites must scale to handle unpredictable traffic spikes.
Build It with Nitrogen: the Fast Off the Block Erlang Web Framework addresses these issues and more. It assumes minimal Linux or JavaScript skills. The easy to-read book guides the reader through seven hands-on projects. Each project builds on the last toward high-level competency. Readers learn Erlang as they go. āNitrogen simplifies development of web applications, making simple things easy and difficult things manageable,ā says Zotonic CMS creator Marc Worrell.
āThis book is ambitious,ā says Nitrogen creator Rusty Klophaus, āIt covers not only Nitrogen and Erlang, but also a bit of OTP, databases, git, web design, and software engineering best practices. And somehow, it does this well by building up from simple concepts in a sort of āSocratic dialogueāāif Socrates had a āCalifornia surferā sense of humor.ā
Build It with Nitrogen: the Fast Off the Block Erlang Web Framework guides web developers step-by-step through the construction of highly reliable web applications using Erlang and the Nitrogen Web Framework.
This easy-to-read book assumes minimal Linux or JavaScript skills; guides the reader through 7 hands-on projects. Each project builds on the last toward high-level competency. Readers learn Erlang as they go. Nitrogen simplifies development of web applications, making simple things easy and difficult things manageable.
Erlang delivers the high availability, massively scalable, soft real-time performance required by banking, e-commerce, computer telephony, and instant messaging applications.
What Youāll Learn in Build It With Nitrogen
- How to build basic CRUD interfaces
- How to build highly dynamic interfaces
- How to work with the templates and the DOM
- How to work with logins and password hashing
- How to use OTP basics with gen_servers and supervisors
- How to use the databases: DETS, Mnesia, and PostgreSQL
- How to interact with external APIs (in our case, retrieving stock quotes)
- How to build your own behaviours and use those to produce Nitrogen pages more rapidly
- How to build custom Nitrogen elements and convert those into plugin libraries
- The basics of web application security
- The basics of using other front-end frameworks (specifically Bootstrap)
- How to avoid potential maintenance traps
- The basics of Git
- Learn Erlang along the way
This comment is making me want to read this book
I believe @Maartz has already started it, so I will be looking forward to hearing his thoughts too!
Haha! Thanks!
It was Lloydās idea to do it as a dialog, and I think it really worked well.
I appreciate the plug!
Yeah still got the Book Club on devtalk. I need to continue reading it. So far so good I liked it!
Whenever I got some more time Iāll go back to the book club.
Awesome! If you stumble across any issues or confusing bits, donāt hesitate to ask.
I bought and read this book. Great thing! Now Iām making an e-commerce application using Nitrogen. By the way, as a build system I migrated to rebar3.
IMO, Nitrogen was ahead of the time when it was created and itās very relevant now.
And conceptually, it eliminates the choice of the back end framework, the frontend framework, as well as an exchange protocol between them. So you can make the entire stack on Erlang, itās very cool. And with less effort, it turns out almost React / Angular look&feel for customers thanks to dynamic content. Soon Iāll see how it behaves in production, the current tests are promising))
Very awesome! So excited to hear about it. Iāve been kicking around ideas for an e-commerce application of my own for a while now.
Regarding rebar3, Iām actively working on some automated tools to migrate existing rebar2-based Nitrogen projects to rebar3 in preparation of Nitrogen 3. Itās been tricky trying to retain backwards compatibility with the current rebar2-based projects, but Iām almost there.
We did a e-commerce system with Nitrogen and Riak when I studied at Uppsala University. A collaboration with Klarna at that time.
Also some of the files. Remember I tried to update it but was missing something.
Iām currently reading the sample of this book and the full version is on the way.
In the chapter 3 (nitroBoard I), after generating the slim project nb
I got the following error.
ā nb (ī master)ā bin/nitrogen console
Exec: /Users/arif/.asdf/shims/../erts-12.2.1/bin/erlexec -boot_var RELTOOL_EXT_LIB /Users/arif/Practice/Erlang/testproj/nb/lib -sasl releases_dir "/Users/arif/Practice/Erlang/testproj/nb/releases" -boot /Users/arif/Practice/Erlang/testproj/nb/releases/2.4.0/nitrogen -mode interactive -config /Users/arif/Practice/Erlang/testproj/nb/etc/app.config -config /Users/arif/Practice/Erlang/testproj/nb/etc/simple_bridge.config -config /Users/arif/Practice/Erlang/testproj/nb/etc/sync.config -args_file /Users/arif/Practice/Erlang/testproj/nb/etc/vm.args -- console
Root: /Users/arif/.asdf/shims/..
bin/nitrogen: line 299: /Users/arif/.asdf/shims/../erts-12.2.1/bin/erlexec: No such file or directory
bin/nitrogen: line 299: exec: /Users/arif/.asdf/shims/../erts-12.2.1/bin/erlexec: cannot execute: No such file or directory
I have installed Erlang through asdf
.
I assume from the error that nitrogen is looking for a directory named erts-12.2.1
somewehre in the ~/.asdf
directory and isnāt finding it.
Edit: Currently, I re-generated the project using full release instead of the slim release to continue reading the book.
Awesome! Glad to hear it!
Yeah, the slim release is looking for an erts-X.Y.Z
directory in the erlang directory.
Glad to hear youāre able to continue plugging along with the full release. That should work for you for now. Iām not familiar with asdf
's conventions as a package manager, so Iāll have to experiment, but I wonāt be spending too much time on it, as Nitrogen 3 is āright around the corner,ā which drops rebar2, finally adopting rebar3/relx and the difference there is just tweaks to the default config file, rather than fully structural things.
If you have other questions, donāt hesitate to ask, and I appreciate you reading!
Thank you!
Will the book update with Nitrogen 3?
I found the directory nitrogen was looking for. Itās ~/.asdf/installs/erlang/24.2.1/erts-12.2.1
.
Right now Iām super tired. Tomorrow I will generate the slim version of the project and try to tell nitrogen where this directory is. I think editing a single file manually for the life of a project wonāt hurt.
Oh, it sure will be! Iām going at this rather slowly as well, because Iām rather dogmatic about retaining backwards compatibility (on top of having a day job and family and the usual).
But absolutely. My goal is to make sure that when N3 is released, that the current edition of the book does not break, while Iāll take some time to update the book to ensure that the āupdatedā version of the book more closely follows the N3 conventions (which are really more like a superset of the OTP conventions). At current, Nitrogen 2 kind of uses its own conventions out of the box and theyāre definitely not OTP standard conventions (the most obvious is the use of the site/
directory as a container for src
, include
, etc. instead of those directories existing in the root of the project directory).
Currently I made it work by adding erlang installation folder to the path, so that the Erlang executable from the installs/erlang/24.2.1/bin
is used instead of the one from shims
folder, and when the script is looking for the erts-12.2.1
folder under the parent directory of bin
, it is finding it.
Excellent! That sounds about right. So glad you were able to figure it out!
Thank you @gumm!
Iām really enjoying this book.
I resumed the book.
Iām following all the steps exactly as instructed. The Listing 3.18 (rr(visitors_db).
) is giving me {error,nofile}
instead of [visitor]
.
Edit: It worked. I think I was running it outside the site
directory.
Oh, good catch. This bit is assuming that sync
has been running to recompile it automatically.
However, if you exit the erlang VM, from the ~/nb
directory:
make
cd site
erl -pa ebin
and it should work.
After learning Nitrogen, I want to use it in some real/toy project as the web app and also for writing the back-end (RESTful APIs) of mobile apps.
Is writing APIs in Nitrogen as easy as writing a web app in it?
Yeah, writing a restful API is quite easy in Nitrogen (Nitrogen - Documentation).
The big thing is to: add this to your module:
An example of a simple GET api would be this.
Request: http://localhost:8000/userinfo?userid=12345
Anticipated Response:
{"name": "Joe", "email": "joe@example.com"}
Hereās what that module could look like:
-module(userinfo).
-export([
get/1
]).
-behaviour(nitrogen_rest).
get(_PathInfo) ->
ID = wf:q(userid),
case db_user:get(ID) of
undefined ->
{404, "Not Found"};
User ->
wf:json_encode(User)
end.
In the above context, User
would be a proplist that looks like like: [{name, <<"Joe">>}, {email, <<"joe@example.com">>}]
That said, if you need a really robust restful API, dipping directly into a cowboy handler would be recommended. But Nitrogen can handle most restful APIs.