<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Node on enten.fr</title>
    <link>http://www.enten.fr/steven/tags/node/</link>
    <description>Recent content in Node on enten.fr</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>fr-FR</language>
    <copyright>(c) 2015 Steven Enten</copyright>
    <lastBuildDate>Sun, 14 Jun 2015 00:00:00 +0000</lastBuildDate>
    <atom:link href="http://www.enten.fr/steven/tags/node/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>kaio</title>
      <link>http://www.enten.fr/steven/kaio/</link>
      <pubDate>Sun, 14 Jun 2015 00:00:00 +0000</pubDate>
      
      <guid>http://www.enten.fr/steven/kaio/</guid>
      <description>

&lt;p&gt;A minimalist middleware to get started faster with Koa.&lt;/p&gt;

&lt;h2 id=&#34;installation&#34;&gt;Installation&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;npm install kaio --save
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;h3 id=&#34;requirements&#34;&gt;Requirements&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;mkdir kaio-app
cd kaio-app
npm install kaio koa-router
touch app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&#34;language-javascript&#34;&gt;// app.js

var kaio = require(&#39;kaio&#39;);
var router = require(&#39;koa-router&#39;);

kaio()
    .setRoot(__dirname)
    .setHost(&#39;127.0.0.1&#39;)
    .setPort(3000)
    .setUri(&#39;/api&#39;)
    .bind(&#39;/&#39;, BaseController)
    .bind(&#39;/books&#39;, BookController)
    .listen();

function *BaseController(next) {
    yield next;

    if (this.res.statusCode === 200)
        return;

    this.body = &#39;Hello world!&#39;;
}

function BookController() {
    var dataset = [
        { title: &amp;quot;The Fellowship of the Ring&amp;quot;, author: &amp;quot;J. R. R. Tolkien&amp;quot;, publication: &amp;quot;1954-07-29&amp;quot; },
        { title: &amp;quot;The Two Towers&amp;quot;, author: &amp;quot;J. R. R. Tolkien&amp;quot;, publication: &amp;quot;1954-11-11&amp;quot; },
        { title: &amp;quot;The Return of the King&amp;quot;, author: &amp;quot;J. R. R. Tolkien&amp;quot;, publication: &amp;quot;1955-10-20&amp;quot; }
    ];

    var list = function *(next) {
        var res = dataset;

        yield next;
        this.body = res;
    };

    var show = function *(next) {
        var title = decodeURI(this.params.title);
        var res = dataset.filter(function(x) {
            return title === x.title;
        }).shift();

        yield next;
        this.body = res;
    };

    return router()
        .get(&#39;/&#39;, list)
        .get(&#39;/:title&#39;, show)
        .middleware();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;run-the-application&#34;&gt;Run the application&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;$ KO_PORT=1333 DEBUG=* node --harmony app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;test-it&#34;&gt;Test it&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;# 3000 is the default port but it is overriden by KO_PORT (1333)

$ curl http://localhost:1333/api/
Not found

$ curl http://localhost:1333/api/
Hello world!

$ curl http://localhost:1333/api/books
[{&amp;quot;title&amp;quot;:&amp;quot;The Fellowship of the Ring&amp;quot;,&amp;quot;author&amp;quot;:&amp;quot;J. R. R. Tolkien&amp;quot;,&amp;quot;publication&amp;quot;:&amp;quot;1954-07-29&amp;quot;},{&amp;quot;title&amp;quot;:&amp;quot;The Two Towers&amp;quot;,&amp;quot;author&amp;quot;:&amp;quot;J. R. R. Tolkien&amp;quot;,&amp;quot;publication&amp;quot;:&amp;quot;1954-11-11&amp;quot;},{&amp;quot;title&amp;quot;:&amp;quot;The Return of the King&amp;quot;,&amp;quot;author&amp;quot;:&amp;quot;J. R. R. Tolkien&amp;quot;,&amp;quot;publication&amp;quot;:&amp;quot;1955-10-20&amp;quot;}]

$ curl http://localhost:1333/api/books/The%2520Two%2520Towers
{&amp;quot;title&amp;quot;:&amp;quot;The Two Towers&amp;quot;,&amp;quot;author&amp;quot;:&amp;quot;J. R. R. Tolkien&amp;quot;,&amp;quot;publication&amp;quot;:&amp;quot;1954-11-11&amp;quot;}
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://cdn.rawgit.com/enten/kaio/master/docs/kaio/0.5.4/index.html&#34;&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;tests&#34;&gt;Tests&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;npm test
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;release-history&#34;&gt;Release History&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;0.5.0 Use confectioner module, add tests and upgrade public API&lt;/li&gt;
&lt;li&gt;0.3.0 Replace custom resolver by &lt;a href=&#34;https://github.com/enten/dotresolver&#34;&gt;dotresolver&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;0.1.0 Initial release&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;credits&#34;&gt;Credits&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/enten&#34;&gt;Steven Enten&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;license&#34;&gt;License&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://github.com/enten/kaio/blob/master/LICENSE.md&#34;&gt;MIT&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>confectioner</title>
      <link>http://www.enten.fr/steven/confectioner/</link>
      <pubDate>Mon, 01 Jun 2015 00:00:00 +0000</pubDate>
      
      <guid>http://www.enten.fr/steven/confectioner/</guid>
      <description>

&lt;p&gt;Simpliest configuration builder which used the environment.&lt;/p&gt;

&lt;h2 id=&#34;installation&#34;&gt;Installation&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;npm install confectioner --save
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&#34;language-javascript&#34;&gt;// example.js

var confectioner = require(&#39;confectioner&#39;);

var config = confectioner({
    env: { envname: &#39;NODE_ENV&#39;, defaultValue: &#39;development&#39; },
    hostname: { envname: &#39;MY_HOST&#39;, defaultValue: &#39;localhost&#39; },
    port: { envname: &#39;MY_PORT&#39;, defaultValue: 1337, type: &#39;int&#39; },
    baseuri: { envname: &#39;MY_BASEURI&#39;, defaultValue: &#39;/myapp&#39; }
});

console.log(config.getValuesMap());

// $ NODE_ENV=production MY_PORT=80 node --harmony example.js
// { env: &#39;production&#39;,
//   hostname: &#39;localhost&#39;,
//   port: &#39;80&#39;,
//   baseuri: &#39;/myapp&#39; }

&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://cdn.rawgit.com/enten/confectioner/master/docs/confectioner/0.1.2/index.html&#34;&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;tests&#34;&gt;Tests&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;npm test
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;release-history&#34;&gt;Release History&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;0.1.0 Initial release&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;credits&#34;&gt;Credits&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/enten&#34;&gt;Steven Enten&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;license&#34;&gt;License&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://github.com/enten/confectioner/blob/master/LICENSE&#34;&gt;MIT&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>dotresolver</title>
      <link>http://www.enten.fr/steven/dotresolver/</link>
      <pubDate>Mon, 13 Apr 2015 00:00:00 +0000</pubDate>
      
      <guid>http://www.enten.fr/steven/dotresolver/</guid>
      <description>

&lt;h2 id=&#34;installation&#34;&gt;Installation&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;npm install dotresolver --save
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;basic-usage&#34;&gt;Basic usage&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&#34;language-javascript&#34;&gt;var R = require(&#39;dotresolver&#39;)(&#39;.&#39;);

// displays the root path .
console.log(R());

// displays the path ./src/controllers/hello.js
console.log(R(&#39;src.controllers&#39;, &#39;hello.js&#39;));

// imports the module hello.js
var hello = R(&#39;src.controllers&#39;, &#39;hello.js&#39;, true);
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;builder-usage&#34;&gt;Builder usage&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&#34;language-javascript&#34;&gt;var Resolver = require(&#39;dotresolver&#39;);

// builds resolver with some aliases
var R = Resolver.Builder(__dirname)
            .set(&#39;ctrl&#39;, &#39;src.controllers&#39;)
            .set(&#39;css&#39;, &#39;public.styles&#39;)
            .get();

// displays the path /home/steven/myapp/public/src/styles/base.css
console.log(R(&#39;css&#39;, &#39;base.css&#39;));

// imports the module hello.js
var hello = R(&#39;ctrl&#39;, &#39;hello.js&#39;, true);
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://cdn.rawgit.com/enten/dotresolver/master/docs/dotresolver/0.3.0/index.html&#34;&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;tests&#34;&gt;Tests&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;npm test
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;release-history&#34;&gt;Release History&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;0.2.8 Fix issue &lt;a href=&#34;https://github.com/enten/dotresolver/issues/3&#34;&gt;#3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;0.2.7 Add helper to create URI resolver&lt;/li&gt;
&lt;li&gt;0.2.6 Fix issue &lt;a href=&#34;https://github.com/enten/dotresolver/issues/2&#34;&gt;#2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;0.2.5 Support object of aliases with setAlias()&lt;/li&gt;
&lt;li&gt;0.2.3 Improve the path building&lt;/li&gt;
&lt;li&gt;0.2.0 Remove real root path features&lt;/li&gt;
&lt;li&gt;0.1.0 Initial release&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;credits&#34;&gt;Credits&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/enten&#34;&gt;Steven Enten&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;license&#34;&gt;License&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://github.com/enten/dotresolver/blob/master/LICENSE&#34;&gt;MIT&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>