<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 12, 2014 at 10:29 PM, rambocoder <span dir="ltr"><<a href="mailto:erlang@rambocoder.com" target="_blank">erlang@rambocoder.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Joe,<div><br></div><div>When I first heard about node, this book provided a gentle introduction by developing a web based calculator:</div>
<div><br></div><div><a href="http://www.packtpub.com/toc/node-web-development-table-contents" target="_blank">http://www.packtpub.com/toc/node-web-development-table-contents</a><br>
</div><div><br></div><div>The book is based on Node 0.4, so none of the examples will work out of the box with current node.</div><div><br></div><div>The book started with canonical "Hello World" example, then it progressed by introducing a package manager and a section on how to make the "Hello World" app run as a daemon and have it autostart on a Linux server (similar to your <a href="http://www.sics.se/~joe/tutorials/web_server/web_server.html" target="_blank">http://www.sics.se/~joe/tutorials/web_server/web_server.html</a>). I really liked the book's guide on "daemonizing" the basic node server (init.d script + forever) because it was such an easy win and within minutes I had the example running on my Linode. <a href="http://www.railstutorial.org/book/beginning" target="_blank">http://www.railstutorial.org/book/beginning</a> a Ruby on Rails tutorial that does something similar by not just introducing ROR in the first chapter, but also getting me started with rvm, gem, git workflow and the free Heroku tier, so by the end of the chapter you have a basic hello world ROR application running on Heroku.</div>

<div><br></div><div>After the "Hello World" example, the Node Web Development book shows how to render a basic table of contents web page with several calculator URLs. Each calculator URL is another example of generating HTML this time with a form and some injected values using string replace, no template language yet.</div>

<div><br></div><div>Then the book proceeds to show how to do routing of URLs and parsing query strings, how to handle POST parameters and return results of calculations using just node, no 3rd party libraries.</div><div>
<br>
</div><div>Once the basic calculator is developed, the author asks: "What complete web server features are missing?" and introduces Connect middleware. Logic code of the calculator remains intact, but web server startup and routing code get's rewritten to use Connect in addition to adding Connect's static content handling and Connect's logger. Once Connect based calculator is running, he introduces Express web framework and EJS templating engine, changing string based HTML generation into an EJS templates, rewriting routing into parametrized Express based routing and he adds Error pages.</div>

<div><br></div><div>Before Cowboy, Misultin was all the rage, it provided short and sweet examples of simple applications in one Erlang file <a href="https://code.google.com/p/misultin/wiki/ExamplesPage" target="_blank">https://code.google.com/p/misultin/wiki/ExamplesPage</a> and before Misultin, Mochiweb was the go to web server for one pager examples, such as <a href="http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1" target="_blank">http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1</a> and in Kevin Smith's screencasts <a href="http://pragprog.com/screencasts/v-kserl/source_code" target="_blank">http://pragprog.com/screencasts/v-kserl/source_code</a> Episode 6, Adding REST using Mochiweb </div>

<div><br></div><div>Cowboy "Hello World" can also be presented as 1 file, check out Elixir's Plug Hello World example, <a href="https://github.com/elixir-lang/plug/blob/master/README.md#hello-world" target="_blank">https://github.com/elixir-lang/plug/blob/master/README.md#hello-world</a></div>
</div></blockquote><div><br></div><div>*very* interesting - uses cowboy :-) </div><div><br></div><div>Now why can't we do that? - this code is also superficially similar to the node version</div><div>not a bad thing I think.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<div><br></div><div>I think it would be awesome to have an erlang tutorial that would teach how to build a web app while doing a compare and contrast to nodejs code.</div></div></blockquote><div><br></div><div>Absolutely - I'd like to learn node *properly* - run to completion in a callback</div>
<div>is the very "interesting" idea (pre 1957 if the wikipedia is correct).</div><div><br></div><div>(Time sharing was invented while people were waiting for jobs to complete :-)</div><div><br></div><div>/Joe</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Cheers,</div><div><br></div><div>
rambocoder</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Thu, Jun 12, 2014 at 10:54 AM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Re: Garrett's great talk at EUC2014<div><br></div><div>The point has been made many times before that </div>

<div>"There are no easy Erlang getting started guides"</div><div><br></div><div>So I thought I'd take a look at Node.js.</div>
<div><br></div><div>The node js home page (node.js) starts with a simple example</div><div><br></div><div><br></div><div><quote></div><div>var http = require('http');</div><div>http.createServer(function (req, res) {</div>


<div>  res.writeHead(200, {'Content-Type': 'text/plain'});</div><div>  res.end('Hello World\n');</div><div>}).listen(1337, '127.0.0.1');</div><div>console.log('Server running at <a href="http://127.0.0.1:1337/'" target="_blank">http://127.0.0.1:1337/'</a>);</div>


<div><br></div><div>To run the server, put the code into a file example.js and execute it with the node program from the command line:</div><div><br></div><div>% node example.js</div><div>Server running at <a href="http://127.0.0.1:1337/" target="_blank">http://127.0.0.1:1337/</a></div>


<div></endquote></div><div><br></div><div>It's pretty easy to knock up an almost identical example in Erlang - using any of the well-known web</div><div>servers in the background, unfortunately this has not been done, or if it has been done</div>


<div>it's not easy to find the examples (or if there are examples I can't find them)</div><div><br></div><div>I was vaguely thinking of making some examples that are more-or-less isomorphic to the</div><div>node.js examples and then applying small transformation steps to turn then from idiomatic node.js code to idiomatic Erlang code.</div>


<div><br></div><div>Although I could find a simple hello world example in node.js I could not find a tutorial that</div><div>started with a simple example and then built on it in very small steps adding routing, authentication,</div>


<div>database access and so on.</div><div><br></div><div>Does anybody know of some examples of node.js that could be used for this.</div><div> </div><div>Cheers</div><span><font color="#888888"><div><br></div>
<div>/Joe</div><div><br></div></font></span></div>
<br></div></div><div class="">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></div></blockquote></div><br></div>
</blockquote></div><br></div></div>