<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Henri Bergius - Nodejs</title>
    <description>Latest posts in category 'nodejs'</description>
    <link>https://bergie.iki.fi</link>
    <language>en</language>
    <lastBuildDate>Tue, 05 May 2026 19:17:08 +0000</lastBuildDate>
    
    <item>
      
      <title>Flying a Quadrocopter with NoFlo</title>
      <description>&lt;p&gt;The &lt;a href=&quot;http://ardrone2.parrot.com/&quot;&gt;Parrot AR.Drone&lt;/a&gt; is quite a lot of fun, and also &lt;a href=&quot;http://nodecopter.com/&quot;&gt;quite hackable&lt;/a&gt;. We recently got one, and the first thing to do was to connect the excellent &lt;a href=&quot;https://github.com/felixge/node-ar-drone&quot;&gt;Node.js ar-drone module&lt;/a&gt; with the &lt;a href=&quot;https://noflojs.org/&quot;&gt;NoFlo&lt;/a&gt; flow-based programming framework.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/ardrone.png&quot; alt=&quot;AR.Drone and a NoFlo flow&quot; /&gt;&lt;/p&gt;

&lt;p&gt;While &lt;a href=&quot;https://github.com/noflo/noflo-ardrone#todo&quot;&gt;quite a lot of work&lt;/a&gt; remains, it was already very satisfying to see how the drone was able to fly patterns based on the NoFlo graphs we created.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/takeoffland.png&quot; alt=&quot;NoFlo graph for take off and land&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This will obviously be more interesting when we have the rest of the motion commands implemented, and can start reading the output of the various sensors on the drone to make it react to its environment. Also interesting would be to connect this to the various other &lt;a href=&quot;https://noflojs.org/library/&quot;&gt;NoFlo libraries&lt;/a&gt; so that the Drone could be controlled by other protocols, or could react to things happening in other web services.&lt;/p&gt;

&lt;p&gt;You can see some example flows in &lt;a href=&quot;http://cannonerd.wordpress.com/&quot;&gt;Susanna’s&lt;/a&gt; &lt;a href=&quot;https://github.com/cannonerd/droning&quot;&gt;droning project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;NoFlo and flying robots. What could go wrong? Just a little hint from &lt;a href=&quot;https://twitter.com/bergie/status/327906353957990400/photo/1&quot;&gt;back in April&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/skynet-small.png&quot; alt=&quot;skynet likes NoFlo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;NoFlo Kickstarter&lt;/a&gt; reached 100% of the funding goal this morning! Now that things are going smoothly there, I can focus more on this and &lt;a href=&quot;https://noflojs.org/example/&quot;&gt;other examples&lt;/a&gt;. Stay tuned!&lt;/em&gt;&lt;/p&gt;
</description>
      <pubDate>Mon, 09 Sep 2013 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2Fnoflo-ardrone%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/noflo-ardrone/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/noflo-ardrone/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>Why did I reimplement Jekyll using NoFlo</title>
      <description>&lt;p&gt;&lt;a href=&quot;http://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt; is a delightful piece of software. A Ruby application that turns your Markdown and HTML files to a nicely constructed static website. Since the generated site is static, you can deploy and serve it from anywhere with no security or performance concerns. As a matter of fact, &lt;a href=&quot;http://bergie.iki.fi/&quot;&gt;this site&lt;/a&gt; is &lt;a href=&quot;http://bergie.iki.fi/colophon/&quot;&gt;built&lt;/a&gt; with Jekyll.&lt;/p&gt;

&lt;p&gt;For websites that don’t need to offer dynamic functionality this is in many ways the culmination of &lt;a href=&quot;http://bergie.iki.fi/blog/decoupling_content_management/&quot;&gt;Decoupled Content Management&lt;/a&gt; — you can write the post using whatever editor, use GitHub as the content repository, and deploy the pages to any web server you want.&lt;/p&gt;

&lt;p&gt;If you’ve been to &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;our Kickstarter project&lt;/a&gt; you probably know that I’ve reimplemented Jekyll using the &lt;a href=&quot;https://noflojs.org/&quot;&gt;NoFlo&lt;/a&gt; flow-based programming environment. &lt;em&gt;If I’m so happy with Jekyll as it is, why would I do such a thing?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;introducing-noflo-jekyll&quot;&gt;Introducing noflo-jekyll&lt;/h2&gt;

&lt;p&gt;Before I go to the reasons, let me briefly introduce the project itself: &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll&quot;&gt;noflo-jekyll&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just like any flow-based program, the NoFlo reimplementation of Jekyll is built out of a graph. Here is how the main graph of the application looks like when loaded via the NoFlo UI prototype:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://d2vqpl3tx84ay5.cloudfront.net/noflo-jekyll.png&quot;&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/noflo-jekyll-small.png&quot; alt=&quot;NoFlo Jekyll main graph&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quite a few of the boxes you see in that graph are actually &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll/tree/master/graphs&quot;&gt;subgraphs&lt;/a&gt;. Since the UI is still under work, the subgraphs have been defined in the more text editor friendly &lt;a href=&quot;https://noflojs.org/documentation/fbp/&quot;&gt;.fbp syntax&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In total at the current version the graphs contain &lt;strong&gt;107 nodes&lt;/strong&gt;. Most of these running a component from the extensive &lt;a href=&quot;https://noflojs.org/library/&quot;&gt;NoFlo component libraries&lt;/a&gt;, but there are also &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll/tree/master/components&quot;&gt;&lt;strong&gt;4 custom components&lt;/strong&gt;&lt;/a&gt; built for this project. These components put together are under 500 lines of code, and everything else is using 100% reusable code from existing libraries. Not bad compared to the size of the original Jekyll code base at over 16k LoC!&lt;/p&gt;

&lt;p&gt;You can grab the &lt;a href=&quot;https://npmjs.org/package/noflo-jekyll&quot;&gt;first release of noflo-jekyll&lt;/a&gt; right now from NPM. Please refer to &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll#readme&quot;&gt;the README&lt;/a&gt; on how to use it.&lt;/p&gt;

&lt;h2 id=&quot;where-this-is-coming-from&quot;&gt;Where this is coming from&lt;/h2&gt;

&lt;p&gt;When I started working with the rest of &lt;a href=&quot;https://www.facebook.com/thegridio&quot;&gt;The Grid&lt;/a&gt; team last year, Jekyll development had practically stopped. It looked like nothing was happening in that community. Since Jekyll was something we very much wanted to utilize for various projects, the situation looked a little bit risky.&lt;/p&gt;

&lt;p&gt;Since we’re very much a NoFlo shop, it felt natural to take Jekyll as sort of a specification, and reimplement it using FBP techniques. Initially this was an internal effort, but then we decided, very much in the nature of &lt;a href=&quot;http://tom.preston-werner.com/2011/11/22/open-source-everything.html&quot;&gt;GitHub’s “open source (nearly) everything”&lt;/a&gt; philosophy, that this should be opened as well.&lt;/p&gt;

&lt;p&gt;I got noflo-jekyll into a running state in about a week, and then moved my attention to other things we needed to build. And so the finishing touches and a public release were postponed to a better day.&lt;/p&gt;

&lt;p&gt;As it happens, &lt;a href=&quot;http://blog.parkermoore.de/2013/05/06/jekyll-1-dot-0-released/&quot;&gt;Jekyll development resumed&lt;/a&gt; pretty soon after that. But there are still many reasons why noflo-jekyll can be quite cool.&lt;/p&gt;

&lt;h2 id=&quot;benefits-of-the-noflo-port&quot;&gt;Benefits of the NoFlo port&lt;/h2&gt;

&lt;p&gt;Here are some reasons why especially Node.js developers should care about this project:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pure JavaScript&lt;/strong&gt;, no need for Ruby or other runtimes in your environment. Especially handy if you’re using &lt;a href=&quot;http://gruntjs.com/&quot;&gt;Grunt&lt;/a&gt; for site generation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Other data sources&lt;/strong&gt;, in NoFlo everything is just a flow of data. You could easily plug in other data sources than the file system. For example, database query results&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Different converters&lt;/strong&gt;, don’t want to use Markdown? Just plug in your own mark-up processor component&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Different template engines&lt;/strong&gt;, don’t want to use Liquid? Just plug in your own template processor component&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use as library or executable&lt;/strong&gt;, this Jekyll implementation is just a NoFlo graph. You can use it in &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll#usage-in-noflo-graphs&quot;&gt;other NoFlo applications&lt;/a&gt;, as &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll#command-line-usage&quot;&gt;a Node.js module&lt;/a&gt;, or as &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll#command-line-usage&quot;&gt;a command-line executable&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, as with any reimplementation of a application being actively developed, there are also some &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll#known-issues-and-differences-with-ruby-jekyll&quot;&gt;potential caveats&lt;/a&gt; to observe.&lt;/p&gt;

&lt;h2 id=&quot;a-noflo-example&quot;&gt;A NoFlo example&lt;/h2&gt;

&lt;p&gt;Most of the existing NoFlo applications out there are dealing with various business processes, and so very little of that is available out in the open. As such, &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll&quot;&gt;noflo-jekyll&lt;/a&gt; can probably show how to build bigger systems out of flow-based graphs, and also how to connect them with the rest of the Node.js ecosystem.&lt;/p&gt;

&lt;p&gt;noflo-jekyll is now available under the MIT license for your static site generation needs. But as it happens, it wasn’t the only interesting NoFlo example to be released this week. You may want to also check out how to &lt;a href=&quot;https://github.com/kenhkan/noflo-woute#readme&quot;&gt;handle HTTP requests in NoFlo&lt;/a&gt; with the Woute module. There is even &lt;a href=&quot;https://github.com/kenhkan/noflo-woute/tree/master/examples/echo_server&quot;&gt;an example project&lt;/a&gt; available.&lt;/p&gt;

&lt;h2 id=&quot;keeping-up-with-jekyll&quot;&gt;Keeping up with Jekyll&lt;/h2&gt;

&lt;p&gt;To realize the benefits of flow-based static site generation, it is quite important to keep the NoFlo reimplementation up-to-speed with things changing in Jekyll-land.&lt;/p&gt;

&lt;p&gt;Because of this, the most important part of our automated tests is comparing results between a site generated by the original Jekyll program, and the NoFlo version. This means that when new features are added to Jekyll, we can follow the &lt;a href=&quot;http://www.jamesshore.com/Blog/Red-Green-Refactor.html&quot;&gt;red-green-refactor&lt;/a&gt; style of test-driven development, and add these features to the &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll/tree/master/test/fixtures&quot;&gt;test site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I’ve been happily building &lt;a href=&quot;http://bergie.iki.fi/&quot;&gt;my blog&lt;/a&gt; and the &lt;a href=&quot;https://noflojs.org/&quot;&gt;NoFlo site&lt;/a&gt; with this for a while, and except for some minor templating and Markdown handling differences between the Node.js and Ruby versions of those libraries, things are looking solid. If you find something that doesn’t work with the site or templates you have, please &lt;a href=&quot;https://github.com/the-grid/noflo-jekyll/issues&quot;&gt;let us know&lt;/a&gt;!&lt;/p&gt;
</description>
      <pubDate>Mon, 12 Aug 2013 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2Fnoflo-jekyll%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/noflo-jekyll/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/noflo-jekyll/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>My interview on the origins of NoFlo</title>
      <description>&lt;p&gt;&lt;a href=&quot;https://vimeo.com/68285726&quot;&gt;Here&lt;/a&gt; is a video interview of me talking about the origins of &lt;a href=&quot;https://noflojs.org/&quot;&gt;NoFlo&lt;/a&gt;, the flow-based programming environment for JavaScript:&lt;/p&gt;

&lt;iframe src=&quot;https://player.vimeo.com/video/68285726?title=0&amp;amp;byline=0&amp;amp;portrait=0&quot; width=&quot;640&quot; height=&quot;360&quot; frameborder=&quot;0&quot; webkitallowfullscreen=&quot;&quot; mozallowfullscreen=&quot;&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;You’ve seen short pieces from this in the &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;NoFlo Kickstarter video&lt;/a&gt;, but most of the material is new. This was shot when &lt;a href=&quot;http://bergie.iki.fi/blog/noflo-two-years/&quot;&gt;NoFlo turned two&lt;/a&gt;, and so I’m obviously spending some time talking about where things came from.&lt;/p&gt;

&lt;p&gt;The video should work well to support the &lt;a href=&quot;http://bergie.iki.fi/blog/noflo-kickstarter-launch/&quot;&gt;hacker’s perspective&lt;/a&gt; of our funding campaign. Please &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;support us&lt;/a&gt; and spread the word!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;It is pretty amazing to think that since &lt;a href=&quot;http://bergie.iki.fi/blog/noflo-kickstarter-launch/&quot;&gt;my last post&lt;/a&gt; on Friday, we’ve almost doubled the amount of contributions. Thanks to all the &lt;strong&gt;nearly 500 backers&lt;/strong&gt; who have already helped us to change the world of programming!&lt;/em&gt;&lt;/p&gt;
</description>
      <pubDate>Tue, 06 Aug 2013 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2Finterview-noflo-origins%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/interview-noflo-origins/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/interview-noflo-origins/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>NoFlo Kickstarter, the hacker's perspective</title>
      <description>&lt;p&gt;This has been a big week for &lt;a href=&quot;https://noflojs.org/&quot;&gt;NoFlo&lt;/a&gt;, the flow-based programming environment for JavaScript. Yesterday we released &lt;a href=&quot;https://github.com/noflo/noflo/releases/tag/0.4.0&quot;&gt;NoFlo 0.4&lt;/a&gt;, which added support for running flow-based programs in web browsers. And today we launched our &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;NoFlo Development Environment effort on Kickstarter&lt;/a&gt;. Before continuing, make sure to watch &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;the video&lt;/a&gt;!&lt;/p&gt;

&lt;iframe width=&quot;480&quot; height=&quot;360&quot; src=&quot;https:&amp;#x2F;&amp;#x2F;www.kickstarter.com&amp;#x2F;projects&amp;#x2F;noflo&amp;#x2F;noflo-development-environment&amp;#x2F;widget&amp;#x2F;video.html&quot; frameborder=&quot;0&quot;&gt; &lt;/iframe&gt;

&lt;p&gt;This is our effort to bring visual and collaborative flow-based tools into the world of mainstream software development. Similar tools are already in use in many specialized industries from movie special effects to hardware simulation, but we programmers still have to &lt;em&gt;construct these complex maps of our software’s control flow&lt;/em&gt; inside our brains based on their textual representation. With &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;your support&lt;/a&gt;, we could change that!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We’ve already reached a third of our goal on the first day. Clearly people see the need for these tools. Exciting times!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The stories from &lt;a href=&quot;http://techcrunch.com/2013/08/01/noflo-launches-kickstarter-campaign-to-provide-a-way-for-everyone-to-understand-and-visualize-code/&quot;&gt;TechCrunch&lt;/a&gt; and &lt;a href=&quot;http://gigaom.com/2013/08/01/noflo-turns-to-kickstarter-to-expand-program-to-help-non-techies-read-code/&quot;&gt;GigaOm&lt;/a&gt; tell the story well for non-programmers. But based on the questions I’ve received today, I thought it would be good to clarify various points from a more programmer-centric point of view.&lt;/p&gt;

&lt;h2 id=&quot;hasnt-visual-programming-been-tried-before&quot;&gt;Hasn’t visual programming been tried before?&lt;/h2&gt;

&lt;p&gt;The story of visual programming tools started with the &lt;a href=&quot;http://youtu.be/QQhVQ1UG6aM&quot;&gt;GRaIL system&lt;/a&gt; of the 60s, and has progressed to tools like &lt;a href=&quot;http://www.ni.com/labview/&quot;&gt;LabView&lt;/a&gt; and &lt;a href=&quot;http://puredata.info/&quot;&gt;Pure Data&lt;/a&gt;. So far none of these tools has reached mainstream acceptance outside of their (sometimes fanatic) industry niches.&lt;/p&gt;

&lt;p&gt;This is partly because these tools were built originally with a particular problem domain in mind, and partly because of the user experience. Execution matters, as we’ve seen so many times in the tech industry. After all, there were tablets a lot before the iPads.&lt;/p&gt;

&lt;p&gt;With &lt;a href=&quot;http://www.kickstarter.com/profile/noflo&quot;&gt;our team&lt;/a&gt; I have the confidence that we have the necessary skills and vision to build something that is actually a pleasure to use, and that makes it truly easier to work with the control flow of your software than it is with the text editors.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is not a rehash of UML&lt;/em&gt;. UML is a diagram mapping out object-oriented constructs, often used for code generation. NoFlo graphs instead are only the &lt;em&gt;coordination layer&lt;/em&gt; that manages the control flow of your software. The components are still handcrafted and unit-tested code that NoFlo merely wires together at runtime, following the edges specified in a &lt;a href=&quot;https://noflojs.org/documentation/json/&quot;&gt;JSON file&lt;/a&gt;. No code generation here.&lt;/p&gt;

&lt;h2 id=&quot;why-map-out-the-control-flow&quot;&gt;Why map out the control flow?&lt;/h2&gt;

&lt;p&gt;All software is inherently a graph. Functions call other functions, sending data along. Signals are emitted and connections are made. But outside of some debugging tools we rarely see this in a visual format. Instead, when starting to work on a program you have to parse the code and build this map in your head.&lt;/p&gt;

&lt;p&gt;This imposes a lot of cognitive load that tools like NoFlo could avoid. When you can see visually how things are connected, you can focus on the bigger picture and build the software you need in a more efficient way. This is what &lt;a href=&quot;http://vimeo.com/71278954&quot;&gt;Bret Victor talked about recently&lt;/a&gt;.&lt;/p&gt;

&lt;iframe src=&quot;https://player.vimeo.com/video/71278954?title=0&amp;amp;byline=0&amp;amp;portrait=0&quot; width=&quot;500&quot; height=&quot;281&quot; frameborder=&quot;0&quot; webkitallowfullscreen=&quot;&quot; mozallowfullscreen=&quot;&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;h2 id=&quot;what-is-the-role-for-code-then&quot;&gt;What is the role for code, then?&lt;/h2&gt;

&lt;p&gt;However, there still remains a role for text-based code. The actual components, the boxes in the graph, are still written out in JavaScript. But since they’re isolated from their surroundings until a NoFlo graph wires them together, each component can focus on accomplishing a single task well.&lt;/p&gt;

&lt;p&gt;My original &lt;a href=&quot;http://bergie.iki.fi/blog/inspiration-for-fbp-ui/&quot;&gt;NoFlo UI prototype&lt;/a&gt; already included the code editor for modifying and creating new components. By the principles of &lt;a href=&quot;http://en.wikipedia.org/wiki/Test-driven_development&quot;&gt;TDD&lt;/a&gt;, each component is always edited alongside its unit tests, and the tests can be run at any point with a single click. We’re now bringing that back into the new UI:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://d2vqpl3tx84ay5.cloudfront.net/noflo-ui-code.jpg&quot;&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/noflo-ui-code-small.jpg&quot; alt=&quot;Editing code in the NoFlo UI&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For those who don’t want this UI, NoFlo is still fully usable also without it. As a matter of fact, we don’t have a UI before the Kickstarter succeeds, and yet many companies are already building their applications with NoFlo. One way is by using the &lt;a href=&quot;https://noflojs.org/documentation/fbp/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.fbp&lt;/code&gt; language&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;why-now&quot;&gt;Why now?&lt;/h2&gt;

&lt;p&gt;Another reason why the &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;NoFlo development environment&lt;/a&gt; may succeed where many others failed is that programming has changed.&lt;/p&gt;

&lt;p&gt;We no longer target a single protocol — whether the Win32 API or HTTP — in our applications. Instead, we need to talk multiple protocols and with multiple devices at the same time. Even just dealing with both REST and WebSockets is difficult to many traditional programming environments.&lt;/p&gt;

&lt;p&gt;The other big change is the usage of &lt;a href=&quot;http://bergie.iki.fi/blog/internet-application-blueprint/&quot;&gt;different web APIs&lt;/a&gt; as part of your applications. Authentication, handling asynchronous requests and services that are sometimes down can be a pain.&lt;/p&gt;

&lt;p&gt;NoFlo brings a &lt;em&gt;controlling layer&lt;/em&gt; to your software that allows you to map out these scenarios and isolate the handling of each protocol or API into its own set of small, simple components.&lt;/p&gt;

&lt;h2 id=&quot;where-could-this-be-used&quot;&gt;Where could this be used?&lt;/h2&gt;

&lt;p&gt;Many of the nodal editing tools built in the past have been very domain-specific. However, &lt;a href=&quot;http://en.wikipedia.org/wiki/Flow-based_programming&quot;&gt;flow-based programming&lt;/a&gt; is a general software development paradigm. NoFlo has already been used for a wide variety of tasks, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Business data extraction and reporting&lt;/li&gt;
  &lt;li&gt;Automating billing workflows&lt;/li&gt;
  &lt;li&gt;Receiving, routing, and sending text messages&lt;/li&gt;
  &lt;li&gt;Static site generation&lt;/li&gt;
  &lt;li&gt;Building server-side web applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we &lt;a href=&quot;https://github.com/noflo/noflo/releases/tag/0.4.0&quot;&gt;added browser support&lt;/a&gt; it will be possible to also build physics-based user interfaces with NoFlo. There should be some interesting examples of that coming up soon.&lt;/p&gt;

&lt;p&gt;NoFlo being a general JavaScript library could in future enable us to coordinate the flows also in new kinds of places like desktop applications. There are &lt;a href=&quot;http://www.gnome.org/&quot;&gt;several&lt;/a&gt; &lt;a href=&quot;http://kde.org/&quot;&gt;desktop&lt;/a&gt; &lt;a href=&quot;http://en.wikipedia.org/wiki/Windows_Runtime&quot;&gt;environments&lt;/a&gt; where JavaScript is a first-class citizen. Combining flow-based interactions with declarative UI definitions could be something very powerful!&lt;/p&gt;

&lt;p&gt;Many of the giants of the software industry, like Google, Facebook, Microsoft, Adobe, and Mozilla are all working on improving the JavaScript development tools. It would be awesome to have their support for what we’re doing.&lt;/p&gt;

&lt;h2 id=&quot;how-about-open-source&quot;&gt;How about open source?&lt;/h2&gt;

&lt;p&gt;If you’re following this blog, you probably know that I feel strongly for software freedom. Everything I’ve done during my &lt;a href=&quot;http://www.linkedin.com/in/bergie&quot;&gt;professional career&lt;/a&gt; has been possible only thanks to the open source community.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://noflojs.org/&quot;&gt;NoFlo&lt;/a&gt; and the UI we’re building are and will remain open source available under the &lt;a href=&quot;https://en.wikipedia.org/wiki/MIT_License&quot;&gt;MIT license&lt;/a&gt;. As a matter of fact, the UI is designed to not only work with NoFlo, but also to be adaptable to work with other flow-based systems. I feel this is an area with a lot of potential for collaboration with the various functional and dataflow projects out there.&lt;/p&gt;

&lt;p&gt;We will however be offering a hosted version of the software for a fee. The various &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;Kickstarter rewards&lt;/a&gt; will give our backers an early and cheaper access to that.&lt;/p&gt;

&lt;p&gt;But still, you’ll always be able to run the whole stack on your own infrastructure if you choose to do so.&lt;/p&gt;

&lt;h2 id=&quot;what-happens-next&quot;&gt;What happens next?&lt;/h2&gt;

&lt;p&gt;Our &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;Kickstarter campaign&lt;/a&gt; has been up for less than a day, and we’re already &lt;em&gt;above 30%&lt;/em&gt; of our goal. This makes me quite optimistic for the effort. But of course we won’t succeed without the help of the wider open source and JavaScript community!&lt;/p&gt;

&lt;p&gt;There are still quite a lot of days left in the campaign. Tonight I’ll be flying back to Europe, and then we’ll focus on the next steps.&lt;/p&gt;

&lt;p&gt;One important area of attention is publishing more demos and examples of NoFlo in real-world use. I hope by early next week we’ll be able to show a few applications running on both browser and Node.js. I will also publish our flow-based port of the &lt;a href=&quot;http://jekyllrb.com/&quot;&gt;Jekyll static site generator&lt;/a&gt;. These should help people getting started with this style of programming.&lt;/p&gt;

&lt;p&gt;We also have quite a lot of content lined up and waiting for editing. Something of interest to everybody working with flow-based or functional programming will be the long cut of the interview we made with &lt;a href=&quot;http://en.wikipedia.org/wiki/John_Paul_Morrison&quot;&gt;J. Paul Morrison&lt;/a&gt;, the father of FBP. My hope is that video will be live by the end of the next week.&lt;/p&gt;

&lt;p&gt;If you’re interested in the developments, make sure to follow NoFlo on &lt;a href=&quot;https://twitter.com/noflo&quot;&gt;Twitter&lt;/a&gt;, &lt;a href=&quot;https://www.facebook.com/noflo&quot;&gt;Facebook&lt;/a&gt;, or &lt;a href=&quot;https://plus.google.com/u/0/112372998187205178398&quot;&gt;Google+&lt;/a&gt;. If you back &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;our campaign&lt;/a&gt;, you’ll also receive the updates via Kickstarter.&lt;/p&gt;

&lt;p&gt;Thanks everybody for helping to make this possible! Keep spreading the world and giving &lt;a href=&quot;http://www.kickstarter.com/projects/noflo/noflo-development-environment&quot;&gt;your support&lt;/a&gt;!&lt;/p&gt;
</description>
      <pubDate>Thu, 01 Aug 2013 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2Fnoflo-kickstarter-launch%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/noflo-kickstarter-launch/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/noflo-kickstarter-launch/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>NoFlo: two years of flow-based programming</title>
      <description>&lt;p&gt;&lt;a href=&quot;https://noflojs.org&quot;&gt;NoFlo&lt;/a&gt; — the flow-based programming system I started — is now two years old. I &lt;a href=&quot;https://github.com/noflo/noflo/commit/04698a77272d9cd552ac57ca511ec8f05696ea40&quot;&gt;pushed the first commits&lt;/a&gt; to GitHub on June 5th 2011 from &lt;a href=&quot;http://www.hackerdojo.com/&quot;&gt;Hacker Dojo&lt;/a&gt; in Mountain View. To get us started with the story, I’ll let &lt;a href=&quot;http://en.wikipedia.org/wiki/Flow-based_programming&quot;&gt;Wikipedia summarize&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Flow-based programming (FBP) is a programming paradigm that defines applications as networks of “black box” processes, which exchange data across predefined connections by message passing, where the connections are specified externally to the processes. These black box processes can be reconnected endlessly to form different applications without having to be changed internally.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While flow-based programming is still far from mainstream, it has been great to watch to the community grow around NoFlo.&lt;/p&gt;

&lt;p&gt;There are several start-ups using it as their base infrastructure, with several of their engineers contributing to the open source effort. I’ve personally used the system for quite a wide range of tasks from &lt;a href=&quot;http://bergie.iki.fi/blog/8998693776/&quot;&gt;web services&lt;/a&gt; and &lt;a href=&quot;http://bergie.iki.fi/blog/business_analytics_with_couchdb_and_noflo/&quot;&gt;document transformations&lt;/a&gt; to handling payments and user on-boarding processes.&lt;/p&gt;

&lt;h2 id=&quot;why-i-started-noflo&quot;&gt;Why I started NoFlo&lt;/h2&gt;

&lt;p&gt;Two years ago I was undergoing a transition from PHP and Python to the JavaScript world, largely lured by the benefits of a &lt;a href=&quot;http://bergie.iki.fi/blog/the_universal_runtime/&quot;&gt;universal runtime&lt;/a&gt; and the event-based multi-protocol paradigm &lt;a href=&quot;http://nodejs.org/&quot;&gt;Node.js&lt;/a&gt; offers.&lt;/p&gt;

&lt;p&gt;While new programming languages and environments are easy to get into, this transition provided yet another point where I would have to sit down and port over all the little libraries and utilities I’ve grown to rely on over the years.&lt;/p&gt;

&lt;p&gt;I wondered if there could be a better way.&lt;/p&gt;

&lt;p&gt;To figure that out, I spent the time I had when traveling between conferences and hackathons of the &lt;a href=&quot;http://www.iks-project.eu/&quot;&gt;IKS Project&lt;/a&gt; reading various computer science papers on different programming paradigms. Eventually I stumbled upon some mentions of flow-based programming. I dug deeper, and finally read the canonical book on the subject — Paul Morrison’s &lt;a href=&quot;http://amzn.com/1451542321&quot;&gt;Flow-based programming, 2nd edition&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Having worked with component architectures and Unix pipes before, the idea resonated with me. To think things through, I took the excuse of having some meetings in Portland to &lt;a href=&quot;http://www.flickr.com/photos/bergie/sets/72157626665916769/&quot;&gt;drive up there&lt;/a&gt; following the beautiful &lt;a href=&quot;http://en.wikipedia.org/wiki/California_State_Route_1&quot;&gt;California 1&lt;/a&gt; coastal road. Couple of days alone in a car is a great way to let your mind flow!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/oregon-coast.jpg&quot; alt=&quot;The coastal road in Oregon&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Implementing your own is usually the best method for learning a new concept, and so when I got back to the Bay Area, I decided to write an &lt;a href=&quot;https://noflojs.org&quot;&gt;FBP system of my own&lt;/a&gt; on Node.js.&lt;/p&gt;

&lt;p&gt;I also kept a &lt;a href=&quot;http://en.wikipedia.org/wiki/Qaiku&quot;&gt;Qaiku&lt;/a&gt; thread on the things I discovered, parts of which I later &lt;a href=&quot;http://bergie.iki.fi/blog/flow-based-programming-is-interesting/&quot;&gt;republished on this site&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;beyond-oop&quot;&gt;Beyond OOP&lt;/h2&gt;

&lt;p&gt;Object-oriented programming and Model-View-Controller have been the dominant programming paradigms since the desktop computing era of the 90s, even while the world has become more connected and multi-device. While these concepts did improve some things, the big promises of programmer productivity and component reuse have mostly been &lt;a href=&quot;http://blog.dmbcllc.com/object-oriented-programming-has-failed-us/&quot;&gt;left unrealised&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Software has &lt;a href=&quot;http://online.wsj.com/article/SB10001424053111903480904576512250915629460.html&quot;&gt;become one of the most important aspects&lt;/a&gt; of business and the society. As an effect, the demand for programmers &lt;a href=&quot;http://blog.nwjobs.com/careercenter/talking_code_demand_for_programmers_software_engineers_outstrips_supply.html&quot;&gt;vastly outstrips&lt;/a&gt; the amount of computer science graduates we’re able to produce.&lt;/p&gt;

&lt;p&gt;The tools side of things isn’t looking much better, either. While IDEs are admittedly improving all the time, most of the talented programmers have ditched them and moved back to the console-based editors of the 80s like vim and Emacs, many following the &lt;a href=&quot;http://blog.sanctum.geek.nz/unix-as-ide-introduction/&quot;&gt;Unix as your IDE&lt;/a&gt; idea. Clearly the productivity boost given by IDEs doesn’t yet match the overhead of using them.&lt;/p&gt;

&lt;p&gt;These areas are where flow-based programming can help.&lt;/p&gt;

&lt;h2 id=&quot;the-logic-is-in-the-graph&quot;&gt;The logic is in the graph&lt;/h2&gt;

&lt;p&gt;When we design software, we usually start by drawing boxes and arrows on a whiteboard. Later on these are then translated to actual software through various text files containing classes, methods, and configuration information.&lt;/p&gt;

&lt;p&gt;As the software evolves, people rarely go back to the original drawing and update it, effectively making the source code only place documenting how different pieces of a system fit together.&lt;/p&gt;

&lt;p&gt;With FBP, the logic of the software is designed as &lt;a href=&quot;http://en.wikipedia.org/wiki/Directed_graph&quot;&gt;a graph&lt;/a&gt; — much like a flowchart — and stays as a graph.&lt;/p&gt;

&lt;p&gt;The boxes of the graph depict various instances of reusable components, and the arrows the wiring connecting their ports together.&lt;/p&gt;

&lt;p&gt;The graph is what FBP systems like NoFlo execute, and it is also something that can be easily drawn on the screen, or even edited visually.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/fbp-ui/drawfbp-small.png&quot; alt=&quot;NoFlo graph in DrawFBP&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We humans &lt;a href=&quot;http://books.google.de/books?id=ffw6aBE-9ykC&amp;amp;lpg=PA1108&amp;amp;ots=baZIBoNyYI&amp;amp;dq=humans%20are%20visual%20creatures&amp;amp;pg=PA1108#v=onepage&amp;amp;q=humans%20are%20visual%20creatures&amp;amp;f=false&quot;&gt;are visual creatures&lt;/a&gt;. We are much better at recognizing shapes and visual connections than at finding them from a jumble of text files.&lt;/p&gt;

&lt;p&gt;Each node (or &lt;em&gt;process&lt;/em&gt; in FBP terminology) of a graph is an instance of a component. Just like objects in OOP can receive and react to messages (&lt;em&gt;method calls&lt;/em&gt;), NoFlo components react to packets they receive through their input ports, process them, and eventually send something to their output ports.&lt;/p&gt;

&lt;p&gt;The graph decides where the output is sent, meaning that the overall behavior of a program can be modified by just rewiring some of these connections. In traditional OOP the connections between various objects are usually hardcoded, or managed by a complicated &lt;a href=&quot;http://en.wikipedia.org/wiki/Dependency_injection&quot;&gt;dependency injection&lt;/a&gt; systems.&lt;/p&gt;

&lt;h2 id=&quot;component-reuse&quot;&gt;Component reuse&lt;/h2&gt;

&lt;p&gt;Because FBP components are just black boxes performing some well-defined task on incoming packets, they can be connected with each other in multitude of different ways to produce a different behaviour. This gives FBP systems a much better scale of code reuse than traditional OOP or procedural environments.&lt;/p&gt;

&lt;p&gt;As an example, my typical NoFlo applications only contain some 5-15% of components written specifically for that project. The rest are all coming from the &lt;a href=&quot;https://npmjs.org/browse/depended/noflo&quot;&gt;growing ecosystem&lt;/a&gt; of ready-made NoFlo components.&lt;/p&gt;

&lt;p&gt;Writing and &lt;a href=&quot;http://bergie.iki.fi/blog/distributing-noflo-components/&quot;&gt;publishing components&lt;/a&gt; is already quite easy, and is becoming even faster and more reliable through tools like the &lt;a href=&quot;https://github.com/noflo/grunt-init-noflo&quot;&gt;Grunt component scaffolder&lt;/a&gt; and &lt;a href=&quot;https://github.com/noflo/noflo-test&quot;&gt;noflo-test&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The more components are out there the less time we need to spend writing code, and the more we can focus on designing the software logic itself.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;noflo-on-the-browser&quot;&gt;NoFlo on the browser&lt;/h2&gt;

&lt;p&gt;Apart of better tooling and more components, the other big improvement in NoFlo has been support for running FBP programs on the client. Originally NoFlo was designed for server-side flows, but thanks to the improving &lt;a href=&quot;http://bergie.iki.fi/blog/sharing-javascript-libraries-node-browser/&quot;&gt;client-side Component ecosystem&lt;/a&gt;, it became feasible to expose the environment also to web browsers.&lt;/p&gt;

&lt;p&gt;This is keeping true with the promises of the universal runtime. With the next release of NoFlo, flow-based programs can be run on pretty much any computing device, whether a Node.js equipped web server, or a smartphone with a browser.&lt;/p&gt;

&lt;p&gt;The ability to run client-side flow-based programs presents new opportunities. There is a tradition of using tools like &lt;a href=&quot;http://www.filterforge.com/features/editor.html&quot;&gt;FilterForge&lt;/a&gt; for visual effects, or &lt;a href=&quot;http://en.wikipedia.org/wiki/Quartz_Composer&quot;&gt;Quartz Composer&lt;/a&gt; for user interaction design. As a matter of fact, &lt;a href=&quot;https://medium.com/the-year-of-the-looking-glass/af182add5a2f&quot;&gt;Facebook Home was designed using flow-based tools&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;…something like Facebook Home is completely beyond the abilities of Photoshop as a design tool. How can we talk about physics-based UIs and panels and bubbles that can be flung across the screen if we’re sitting around looking at static mocks? (Hint: we can’t.) It’s no secret that many of us on the Facebook Design team are avid users of Quartz Composer, a visual prototyping tool that lets you create hi-fidelity demos that look and feel like exactly what you want the end product to be.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since NoFlo graphs run on any device including the tablets and smartphones that the application being designed is likely to target, it can provide an even better environment for such prototyping. There are lots of opportunities for a new tool here, especially given that &lt;a href=&quot;http://www.fcp.co/final-cut-pro/news/932-will-the-end-of-apple-s-quartz-composer-finally-kill-off-final-cut-pro-7-and-its-plugins&quot;&gt;Quartz Composer’s future is quite uncertain&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are already doing some work on &lt;a href=&quot;https://github.com/noflo/noflo/issues/66&quot;&gt;visual interaction components for NoFlo&lt;/a&gt;. This could be huge for NoFlo and FBP in general!&lt;/p&gt;

&lt;h2 id=&quot;ui-is-the-missing-part&quot;&gt;UI is the missing part&lt;/h2&gt;

&lt;p&gt;What we have with NoFlo is already a quite solid programming environment:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://noflojs.org&quot;&gt;Flow-based engine&lt;/a&gt; that works well in both browser and Node.js&lt;/li&gt;
  &lt;li&gt;Growing ecosystem of &lt;a href=&quot;https://npmjs.org/browse/depended/noflo&quot;&gt;reusable open source components&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Framework for quickly &lt;a href=&quot;https://github.com/noflo/grunt-init-noflo&quot;&gt;scaffolding&lt;/a&gt; and &lt;a href=&quot;https://github.com/noflo/noflo-test&quot;&gt;testing&lt;/a&gt; new components&lt;/li&gt;
  &lt;li&gt;Domain-specific language for &lt;a href=&quot;https://github.com/noflo/fbp#language-for-flow-based-programming&quot;&gt;defining NoFlo graphs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, the missing part is a tool that would allow viewing and editing NoFlo graphs visually. Sure, &lt;a href=&quot;http://www.jpaulmorrison.com/cgi-bin/wiki.pl?DrawFBP&quot;&gt;DrawFBP&lt;/a&gt; is there, and can be used with NoFlo. But something fitting modern touchscreen interactions and more connected to the live graphs would be better.&lt;/p&gt;

&lt;p&gt;I did some prototypes on this with &lt;a href=&quot;https://github.com/noflo/noflo-ui&quot;&gt;noflo-ui&lt;/a&gt;, and wrote down &lt;a href=&quot;http://bergie.iki.fi/blog/inspiration-for-fbp-ui/&quot;&gt;bunch of thoughts&lt;/a&gt; on how the graphs would be best shown. There has also been some collaboration with Forrest Oliphant of &lt;a href=&quot;http://meemoo.org/&quot;&gt;Meemoo&lt;/a&gt; fame.&lt;/p&gt;

&lt;p&gt;Last week I sat down with &lt;a href=&quot;http://www.behance.net/leightaylor&quot;&gt;Leigh Taylor&lt;/a&gt;, the original designer behind the &lt;a href=&quot;https://medium.com/&quot;&gt;Medium&lt;/a&gt; blogging platform, to go through the various ideas and concepts we had. Based on this we’re starting to have a quite solid design to continue working with.&lt;/p&gt;

&lt;p&gt;There will be more on that in the near future, but here is a sneak preview:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/fbp-ui/leigh-concept-small.jpg&quot; alt=&quot;Leigh&apos;s NoFlo UI concept&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;telling-the-story-of-noflo&quot;&gt;Telling the story of NoFlo&lt;/h2&gt;

&lt;p&gt;Apart from the user interface, the other important task ahead of us is to grow the community around NoFlo and FBP in general.&lt;/p&gt;

&lt;p&gt;This means producing better documentation, and explaining the concept in conferences and meetups. I gave &lt;a href=&quot;http://youtu.be/pgP4v9b5DvE&quot;&gt;a talk on NoFlo in JS.Everywhere 2011&lt;/a&gt;, but the project has moved quite far ahead since then.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/bergie-noflo-interview.jpg&quot; alt=&quot;Being interviewed on NoFlo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To tell the story of NoFlo and FBP we’re currently filming a set of interviews with the people involved from the different sides. We’re talking with NoFlo contributors, designers, and with people who have years (or even decades!) of experience with flow-based programming. This will hopefully come out next month.&lt;/p&gt;

&lt;p&gt;Expect also more posts and tutorials here &lt;a href=&quot;http://bergie.iki.fi/&quot;&gt;on my blog&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Wed, 05 Jun 2013 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2Fnoflo-two-years%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/noflo-two-years/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/noflo-two-years/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>Writing reusable, multi-platform JavaScript with Component</title>
      <description>&lt;p&gt;I’m currently in the process of porting the &lt;a href=&quot;https://noflojs.org&quot;&gt;NoFlo&lt;/a&gt; Flow-Based Programming environment to run also in the browser. While there are some obvious differences in things like filesystem interaction and component loading, the goal here is to reuse as much of the same code as possible between these two platforms.&lt;/p&gt;

&lt;p&gt;Many of the building blocks are already in place, and so the port should be complete still this week. You can track the work in &lt;a href=&quot;https://github.com/noflo/noflo/issues/63&quot;&gt;issue 63&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; the post below is mostly of historical value. Nowadays I would recommend using NPM for dependency management and &lt;a href=&quot;https://webpack.js.org&quot;&gt;Webpack&lt;/a&gt; for browser builds. For NoFlo, &lt;a href=&quot;https://github.com/noflo/grunt-noflo-browser&quot;&gt;grunt-noflo-browser&lt;/a&gt; provides automation for this.&lt;/p&gt;

&lt;h2 id=&quot;a-fragmented-ecosystem&quot;&gt;A fragmented ecosystem&lt;/h2&gt;

&lt;p&gt;The current client-side JavaScript ecosystem is quite fragmented. While on general level any code can be used anywhere, there are many different approaches at packaging, code loading, and templating. In many ways this resembles the PHP landscape before &lt;a href=&quot;http://bergie.iki.fi/blog/composer_solves_the_php_code-sharing_problem/&quot;&gt;Composer solved the problem there&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On Node.js we haven’t had this problem for a while, as &lt;a href=&quot;https://npmjs.org/&quot;&gt;NPM&lt;/a&gt; provides an excellent way to share and install code. With more than 27000 modules available, it is truly the default solution for JavaScript package management server-side. Some frameworks like Meteor tried to deviate from this by introducing their own package managers, but eventually &lt;a href=&quot;http://meteor.com/blog/2013/04/04/meteor-060-brand-new-distribution-system-app-packages-npm-integration&quot;&gt;came back to the fold&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;module-definitions&quot;&gt;Module definitions&lt;/h3&gt;

&lt;p&gt;There are many different ways for handling loading and encapsulation of JavaScript code. The &lt;a href=&quot;http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html&quot;&gt;module pattern&lt;/a&gt; is quite popular building block. Many also expose their code as &lt;a href=&quot;http://plugins.jquery.com/&quot;&gt;jQuery plugins&lt;/a&gt; even though that really only makes sense or DOM handling.&lt;/p&gt;

&lt;p&gt;Here is how you would define a jQuery plugin:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(function ($) {
  $.fn.somePlugin = function () {
    // some code here
  };
})(jQuery);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Some efforts towards standardization have been made, including the &lt;a href=&quot;http://requirejs.org/docs/whyamd.html&quot;&gt;Asynchronous Module Definition&lt;/a&gt; spec, and the synchronous &lt;a href=&quot;http://dailyjs.com/2010/10/18/modules/&quot;&gt;CommonJS module&lt;/a&gt; spec that Node.js also uses.&lt;/p&gt;

&lt;p&gt;Here is how an AMD wrapper for code looks like:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;define(&apos;somePlugin&apos;, [&apos;jquery&apos;], function ($) {
  return function () {
    // some code here
  };
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The CommonJS definition for something similar would be the following. This will look familiar to Node.js developers:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var $ = require(&apos;jquery&apos;);
exports.someFunction = function () {
  // some code here
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Harmony is the proposed next generation of the JavaScript language, and it includes a &lt;a href=&quot;http://wiki.ecmascript.org/doku.php?id=harmony:modules&quot;&gt;new module syntax&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;module &apos;myModule&apos; {
  import &apos;jquery&apos; as $;
  export function someFunction () {
    // some code here
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It is no wonder many developers feel a bit lost on how they should expose their code or widgets!&lt;/p&gt;

&lt;p&gt;The Harmony module spec may eventually harmonize this, but it will take a while before you can actually ship code like that for even a reasonably majority of browsers.&lt;/p&gt;

&lt;h3 id=&quot;module-installation-and-loading&quot;&gt;Module installation and loading&lt;/h3&gt;

&lt;p&gt;Once you’ve picked the module pattern to follow, the next question is how to actually get your dependencies installed.&lt;/p&gt;

&lt;p&gt;The traditional way is to fetch “known good” versions of the libraries, add them to your project repository, and then just include each library with its own &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;script&lt;/code&gt; tag. But this means having to maintain all the libraries in your own project, and cluttering your repository and change log with them.&lt;/p&gt;

&lt;p&gt;A variant of this is loading common libraries from a Content Delivery Network &lt;a href=&quot;https://developers.google.com/speed/libraries/&quot;&gt;like Google&lt;/a&gt;. This has the advantage that your users won’t have to download something like jQuery separately from each web server, and that you don’t need to duplicate the library files in your own code repository. But at the same time, this relies on the CDN provider not breaking things, and complicates offline usage.&lt;/p&gt;

&lt;p&gt;And you still have to write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;script&lt;/code&gt; tag for each of them.&lt;/p&gt;

&lt;h4 id=&quot;bower&quot;&gt;Bower&lt;/h4&gt;

&lt;p&gt;Twitter’s &lt;a href=&quot;http://twitter.github.io/bower/&quot;&gt;Bower package manager&lt;/a&gt; aims to help with dependency management. You declare the libraries your code needs in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;component.json&lt;/code&gt; file, run Bower, and you’ll get the correct versions downloaded to your system.&lt;/p&gt;

&lt;p&gt;Bower only handles dependency resolution and downloading, and so you’ll still be writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;script&lt;/code&gt; tags for all modules you installed. But at least this allows you to keep the library files out of your repository.&lt;/p&gt;

&lt;h4 id=&quot;requirejs-and-volo&quot;&gt;Require.js and volo&lt;/h4&gt;

&lt;p&gt;The &lt;a href=&quot;http://requirejs.org/&quot;&gt;Require.js&lt;/a&gt; project seeks to solve this by handling module loading for you in an automated manner. They even provide the &lt;a href=&quot;http://volojs.org/&quot;&gt;volo package manager&lt;/a&gt; for installing all the libraries you need.&lt;/p&gt;

&lt;p&gt;Require.js is a quite popular way of solving this, but means that you will need to follow the Asynchronous Module Definition specification with your code.&lt;/p&gt;

&lt;h4 id=&quot;component&quot;&gt;Component&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/component/component&quot;&gt;Component&lt;/a&gt; is a newer solution for this started by TJ Holowaychuk of &lt;a href=&quot;http://expressjs.com&quot;&gt;Express&lt;/a&gt; and &lt;a href=&quot;http://visionmedia.github.io/mocha/&quot;&gt;Mocha&lt;/a&gt; fame.&lt;/p&gt;

&lt;p&gt;The system is explained a lot better in &lt;a href=&quot;http://tjholowaychuk.com/post/27984551477/components&quot;&gt;the introductory blog post&lt;/a&gt;, but in nutshell Component is a combination of a package manager and a module loading system based on CommonJS.&lt;/p&gt;

&lt;p&gt;With Component you can easily write and distribute reusable JavaScript modules, including user interface components that may include HTML templates and CSS. There is a &lt;a href=&quot;http://tjholowaychuk.com/post/37832588021/building-a-date-picker-component&quot;&gt;component writing tutorial&lt;/a&gt; available.&lt;/p&gt;

&lt;p&gt;The Component installer will pull all the dependencies for you, and construct a single, easy-to-include JavaScript file out of them and your own code. &lt;em&gt;If you want to think of it in that way, this is sort of similar to &lt;a href=&quot;http://getcomposer.org/doc/01-basic-usage.md#autoloading&quot;&gt;Composer generating an autoload file&lt;/a&gt; for PHP code&lt;/em&gt;.&lt;/p&gt;

&lt;h3 id=&quot;which-to-choose&quot;&gt;Which to choose?&lt;/h3&gt;

&lt;p&gt;Given the multitude of options available, it can be &lt;a href=&quot;http://stackoverflow.com/questions/14967521/what-is-the-difference-between-component-and-bower&quot;&gt;hard to choose&lt;/a&gt; which one to go with. Eventually a winner may emerge, but in the meanwhile, my approach is the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Component&lt;/strong&gt; for client-side libraries and widgets&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NPM&lt;/strong&gt; for Node.js libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If I was just writing client-side code, Require.js and volo may have been just as good option, at least if I want to deal with AMD.&lt;/p&gt;

&lt;p&gt;However, the big advantage of Component is that it is based on CommonJS modules, which Node.js also uses. With it, I can share library code a lot more easily between browser and the server, the two main platforms of the &lt;a href=&quot;http://bergie.iki.fi/blog/the_universal_runtime/&quot;&gt;Universal Runtime&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;CommonJS modules run nicely in the browser, on Node.js, and &lt;a href=&quot;http://en.wikipedia.org/wiki/Comparison_of_server-side_JavaScript_solutions&quot;&gt;other server-side JavaScript runtimes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;writing-a-multi-platform-library&quot;&gt;Writing a multi-platform library&lt;/h2&gt;

&lt;p&gt;Writing widgets with Component is covered nicely in the &lt;a href=&quot;http://tjholowaychuk.com/post/37832588021/building-a-date-picker-component&quot;&gt;building a date picker component&lt;/a&gt; tutorial, and so I’m focusing on how to build more general-purpose libraries here.&lt;/p&gt;

&lt;h3 id=&quot;getting-component&quot;&gt;Getting Component&lt;/h3&gt;

&lt;p&gt;The first step with Component is getting the tooling in place. Component — like most of the JavaScript dependency managers — is written on top of &lt;a href=&quot;http://nodejs.org/&quot;&gt;Node.js&lt;/a&gt;. It would be possible to implement the &lt;a href=&quot;https://github.com/component/component/wiki/Spec&quot;&gt;Component spec&lt;/a&gt; in other languages for easier integration in their native toolchain, but for now Node.js is what you must install.&lt;/p&gt;

&lt;p&gt;Once you have Node.js running, getting the Component tools is easy:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ sudo npm install -g component
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will give you the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;component&lt;/code&gt; command. You can run it to see the functionality it provides.&lt;/p&gt;

&lt;h3 id=&quot;finding-dependencies&quot;&gt;Finding dependencies&lt;/h3&gt;

&lt;p&gt;The next step is to find the libraries you need. Quite a lot of libraries and widgets are already available, and can be found from &lt;a href=&quot;https://github.com/component/component/wiki/Components&quot;&gt;the Component Wiki&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can also use the Component command to look up modules:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ component search underscore

component/underscore
url: https://github.com/component/underscore
desc: JavaScript&apos;s functional programming helper library.

nathan7/memoize
url: https://github.com/nathan7/memoize
desc: underscore&apos;s memoize
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see, the components use a “GitHub-like” naming scheme of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;vendor&amp;gt;/&amp;lt;module&amp;gt;&lt;/code&gt;. This is again similar to vendor names in Composer:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The package name consists of a vendor name and the project’s name. Often these will be identical - the vendor name just exists to prevent naming clashes. It allows two different people to create a library named json, which would then just be named igorw/json and seldaek/json.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since &lt;a href=&quot;https://noflojs.org&quot;&gt;NoFlo&lt;/a&gt; relies heavily on Node’s &lt;a href=&quot;http://nodejs.org/api/events.html&quot;&gt;event API&lt;/a&gt;, we need to find an equivalent library for Component. After a quick look through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;component search events&lt;/code&gt;, it turns out &lt;a href=&quot;https://github.com/component/emitter&quot;&gt;component/emitter&lt;/a&gt; does the job.&lt;/p&gt;

&lt;h3 id=&quot;the-componentjson-file&quot;&gt;The component.json file&lt;/h3&gt;

&lt;p&gt;Each Component module must provide a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;component.json&lt;/code&gt; file where you declare things like the name of the package, the version number, the software license, the files provided, and the possible dependencies. This is quite similar to the &lt;a href=&quot;http://package.json.nodejitsu.com/&quot;&gt;package.json file in NPM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I’m using a very simplified version of NoFlo’s Graph class as the example here, so I can call the library &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bergie/graph&lt;/code&gt;. Like most JavaScript libraries, this will be under the &lt;a href=&quot;http://en.wikipedia.org/wiki/MIT_License&quot;&gt;MIT license&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
  &quot;name&quot;: &quot;graph&quot;,
  &quot;repo&quot;: &quot;bergie/graph&quot;,
  &quot;description&quot;: &quot;Simple graph class&quot;,
  &quot;license&quot;: &quot;MIT&quot;,
  &quot;version&quot;: &quot;1.0.0&quot;,
  &quot;scripts&quot;: [
    &quot;graph.js&quot;
  ],
  &quot;dependencies&quot;: {
    &quot;component/emitter&quot;: &quot;*&quot;
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For Node.js support you’ll also need a corresponding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package.json&lt;/code&gt; file:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
  &quot;name&quot;: &quot;graph&quot;,
  &quot;description&quot;: &quot;Simple graph class&quot;,
  &quot;main&quot;: &quot;./graph.js&quot;,
  &quot;version&quot;: &quot;1.0.0&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once the dependencies are declared, run the installation:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ component install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The example only uses Node.js’s built-in libraries, so NPM installation is not yet needed. If you add third-party libraries, you need to install them also:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ npm install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;module-code&quot;&gt;Module code&lt;/h3&gt;

&lt;p&gt;Writing a Component module is very similar to writing Node.js modules. Create the file we just declared in the JSON file and open it in your favourite editor.&lt;/p&gt;

&lt;p&gt;Since we’re aiming for multi-platform code, the main difference is dealing with platform-specific differences. For example, the event emitter library in Node.js is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;events&lt;/code&gt;, and the Component equivalent is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;emitter&lt;/code&gt;.Luckily their APIs are exactly the same, so we only have to do loading conditionally:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var EventEmitter;
if (typeof process === &apos;object&apos; &amp;amp;&amp;amp; process.title === &apos;node&apos;) {
  // Node.js
  EventEmitter = require(&apos;events&apos;).EventEmitter;
} else {
  // Browser
  EventEmitter = require(&apos;emitter&apos;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This way, we have the correct event emitter implementation available for our code. Now we just create a constructor function to inherit from that:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// The constructor, just call &quot;super&quot;
function Graph () {
  this.nodes = [];
  EventEmitter.call(this);
}

// Set up inheritance
Graph.prototype = Object.create(EventEmitter.prototype);

// Define methods
Graph.prototype.addNode = function (name) {
  this.nodes.push(name);
  this.emit(&apos;node&apos;, name);
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once the code is there, we need to expose it as a CommonJS module:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;module.exports = Graph;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;running-the-module-in-nodejs&quot;&gt;Running the module in Node.js&lt;/h3&gt;

&lt;p&gt;For Node, this is all we need to do to be able to use our Graph as a module:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Include the module
var Graph = require(&apos;./graph&apos;);

// Instantiate
var g = new Graph();

// Hook into events
g.on(&apos;node&apos;, function (name) {
  console.log(&quot;Node added &quot; + name);
});

// Call a method
g.addNode(&apos;Foo&apos;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Running this should end up with message &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Node added Foo&lt;/code&gt; shown on the console.&lt;/p&gt;

&lt;h3 id=&quot;running-the-module-in-browser&quot;&gt;Running the module in browser&lt;/h3&gt;

&lt;p&gt;To be able to run the module in the browser, we need to run Component’s build process.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ component build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will generate a JavaScript file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;build/build.js&lt;/code&gt; which provides CommonJS module loading support, and all the JavaScript code we’ve declared in the JSON file.&lt;/p&gt;

&lt;p&gt;Now you can include that file in your HTML, and start using the Graph module:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;utf-8&quot;&amp;gt;
    &amp;lt;script src=&quot;./build/build.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
      var Graph = require(&apos;graph/graph.js&apos;);
      var g = new Graph();
      g.on(&apos;node&apos;, function (name) {
        alert(&quot;Node added &quot; + name);
      });
      g.addNode(&apos;foo&apos;);
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Component can be used for solving the JavaScript code-sharing problem. They let you build full applications out of smaller, reusable modules. And thanks to the CommonJS module specification, it is quite easy to write these modules in away which enables them to be used also under Node.js and other JavaScript runtimes.&lt;/p&gt;

&lt;p&gt;This post, and the &lt;a href=&quot;http://tjholowaychuk.com/post/37832588021/building-a-date-picker-component&quot;&gt;date picker tutorial&lt;/a&gt; should give you enough information needed for starting to decouple your front-end applications, and to participate in the emerging &lt;a href=&quot;https://github.com/component/component/wiki/Components&quot;&gt;open source Component ecosystem&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Even with more than &lt;a href=&quot;https://twitter.com/tjholowaychuk/status/316267708381528064&quot;&gt;800 components available&lt;/a&gt;, it is too early to declare Component the winner in the front-end dependency management space, but it is a well-designed system that works quite well.&lt;/p&gt;

&lt;p&gt;I will be utilizing Component for some of my &lt;a href=&quot;https://github.com/bergie&quot;&gt;JavaScript projects&lt;/a&gt; in the future.&lt;/p&gt;
</description>
      <pubDate>Thu, 11 Apr 2013 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2Fsharing-javascript-libraries-node-browser%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/sharing-javascript-libraries-node-browser/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/sharing-javascript-libraries-node-browser/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>GObject Introspection and Node.js</title>
      <description>&lt;p&gt;Unfortunately I will not make it to &lt;a href=&quot;http://www.guadec.org/&quot;&gt;GUADEC&lt;/a&gt; this year. However, here is something new for GNOME developers:&lt;/p&gt;

&lt;p&gt;I wrote last year how &lt;a href=&quot;http://bergie.iki.fi/blog/gobject_introspection_is_coming_to_node-js/&quot;&gt;GObject Introspection was coming to Node.js&lt;/a&gt;. Back then the API was still quite bad, and it was limited in what you could do with it. Since then things have moved forward quite a bit, and today Piotras released &lt;a href=&quot;http://search.npmjs.org/#/gir&quot;&gt;version 0.1.0 of node-gir&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This allows you to interface with any &lt;a href=&quot;https://live.gnome.org/GObjectIntrospection/&quot;&gt;GObject Introspection&lt;/a&gt; capable libraries, including the ones you &lt;a href=&quot;https://github.com/antono/vala-object&quot;&gt;write yourself&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are still some things to be done, especially with stability, but with node-gir Node.js essentially becomes a fully qualified &lt;a href=&quot;http://developer.gnome.org/&quot;&gt;GNOME development environment&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For example, here is a CoffeeScript port of the &lt;a href=&quot;http://developer.gnome.org/gnome-devel-demos/unstable/guitar-tuner.js.html.en&quot;&gt;GNOME Guitar Tuner example&lt;/a&gt;. Still a bit crashy, but at least it shows how the node-gir API works:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/nodejs-guitar-tuner.png&quot; alt=&quot;Node.js Guitar Tuner&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#!/usr/bin/env coffee
# Guitar Tuner
# ------------
#
# This is a CoffeeScript and node-gir port of GNOME&apos;s guitar tuner example from
# &amp;lt;http://developer.gnome.org/gnome-devel-demos/unstable/guitar-tuner.js.html.en&amp;gt;
gir = require &apos;gir&apos;
gtk = gir.load &apos;Gtk&apos;, &apos;3.0&apos;
gst = gir.load &apos;Gst&apos;, &apos;0.10&apos;

gtk.init 0
gst.init 0

guitarwindow = new gtk.Window
  type: gtk.WindowType.toplevel
  title: &quot;Node.js Guitar Tuner&quot;

guitarwindow.on &apos;destroy&apos;, -&amp;gt;
  gtk.mainQuit()
  process.exit()

guitar_box = new gtk.ButtonBox

playSound = (frequency) -&amp;gt;
  console.log frequency
  pipeline = new gst.Pipeline
    name: &apos;note&apos;
  source = new gst.ElementFactory.make &quot;audiotestsrc&quot;, &quot;source&quot;
  sink = new gst.ElementFactory.make &quot;autoaudiosink&quot;, &quot;output&quot;
  source.set_property &quot;freq&quot;, frequency
  pipeline.add source
  pipeline.add sink
  source.link sink
  pipeline.set_state gst.State.PLAYING

addButton = (tune, freq) -&amp;gt;
  button = new gtk.Button
    label: tune
  guitar_box.add button

  button.on &apos;clicked&apos;, -&amp;gt;
    playSound freq

tunes =
  E: 369.23
  A: 440
  D: 587.33
  G: 783.99
  B: 987.77
  e: 1318.5

addButton tune, freq for tune, freq of tunes
guitarwindow.add guitar_box
guitar_box.show_all()

guitarwindow.show()

gtk.main()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;People interested in this effort should watch &lt;a href=&quot;https://github.com/piotras/node-gir&quot;&gt;Piotras’ node-gir repo&lt;/a&gt;. Now the project even has continuous integration &lt;a href=&quot;http://travis-ci.org/#!/piotras/node-gir&quot;&gt;on Travis&lt;/a&gt; using the Midgard GI bindings to test things.&lt;/p&gt;

&lt;p&gt;Of course you can do other cool stuff, like creating a web browser with just couple of lines of JavaScript. Find more &lt;a href=&quot;https://github.com/piotras/node-gir/tree/master/examples&quot;&gt;from the examples folder&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://d2vqpl3tx84ay5.cloudfront.net/nodejs-gir-browser.png&quot; alt=&quot;Web browser in Node.js&quot; /&gt;&lt;/p&gt;
</description>
      <pubDate>Wed, 25 Jul 2012 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2Fnode-gir%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/node-gir/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/node-gir/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>Running CoffeeScript on Microsoft Azure</title>
      <description>&lt;p&gt;It is quite easy to run CoffeeScript applications on &lt;a href=&quot;https://www.windowsazure.com/en-us/&quot;&gt;Azure&lt;/a&gt; now that they support Node.js. You can mostly follow the steps of &lt;a href=&quot;https://www.windowsazure.com/en-us/develop/nodejs/tutorials/web-app-with-express/&quot;&gt;their Node.js and Express tutorial&lt;/a&gt;, with couple of modifications.&lt;/p&gt;

&lt;p&gt;Add a &lt;em&gt;package.json&lt;/em&gt; into your application root and depend on CoffeeScript and Express:&lt;/p&gt;

&lt;pre&gt;{

  &quot;name&quot;: &quot;myapp&quot;,

  &quot;version&quot;: &quot;0.0.1&quot;,

  &quot;dependencies&quot;: {

    &quot;coffee-script&quot;: &quot;*&quot;,&lt;br/&gt;    &quot;express&quot;: &quot;*&quot;&lt;br/&gt;  }

}

&lt;/pre&gt;

&lt;p&gt;Then just have NPM install CoffeeScript by running in the &lt;em&gt;Windows Azure PowerShell for Node.js&lt;/em&gt;:&lt;/p&gt;

&lt;pre&gt;npm install

&lt;/pre&gt;

&lt;p&gt;Once this is done, you can decouple your actual application from the &lt;em&gt;server.js&lt;/em&gt; that Azure uses to start your app. The app (in this case, &lt;em&gt;app.coffee&lt;/em&gt;) itself could look like this:&lt;/p&gt;

&lt;pre&gt;http = require &apos;express&apos;



exports.application = app = http.createServer()&lt;br/&gt;&lt;br/&gt;app.get &apos;/&apos;, (req, res) -&amp;gt;&lt;br/&gt;  res.send &quot;Hello, CoffeeScript on Azure!&quot;

&lt;/pre&gt;

&lt;p&gt;Note that the application doesn&amp;#8217;t start a server, it just exposes it through &lt;em&gt;exports&lt;/em&gt;. Starting can happen in server.js:&lt;/p&gt;

&lt;pre&gt;// Include the CoffeeScript interpreter so that .coffee files will work

var coffee = require(&apos;coffee-script&apos;);



// Include our application file

var app = require(&apos;./app.coffee&apos;);



// Start the server

app.application.listen(process.env.port);&lt;/pre&gt;

&lt;p&gt;And that is it! Now you can work with CoffeeScript just like you would work with any Node.js code on Azure. The only limitation is that if you want to include CoffeeScript files, you need to add the &lt;em&gt;.coffee&lt;/em&gt; suffix to the module require call.&lt;/p&gt;

&lt;p&gt;Here is how the deployed application looks (note that deployment can take a long time. My first deployment was about 30 minutes):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.tumblr.com/tumblr_lwahuukhnX1qhw5db.png&quot;/&gt;&lt;/p&gt;

&lt;p&gt;For data storage and queue handling, the Azure storage services are exposed through the &lt;em&gt;azure&lt;/em&gt; module which is available &lt;a href=&quot;http://search.npmjs.org/#/azure&quot;&gt;via NPM&lt;/a&gt; or &lt;a href=&quot;https://github.com/WindowsAzure/azure-sdk-for-node&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Using Azure workers&lt;/h3&gt;

&lt;p&gt;With cloud services one important part is to split your application into different functional modules. The web server front-ends should only handle HTTP requests and display data, and any heavier computing should be offloaded to separate workers.&lt;/p&gt;

&lt;p&gt;Azure&amp;#8217;s Queue feature provides a handy way of offloading tasks to be handled by worker nodes. For example, we could use a queue to send information on every request received on the web front-end so that workers can process it. For this, we need to install the &lt;em&gt;azure&lt;/em&gt; module. Add this to the dependencies section of your application:&lt;/p&gt;

&lt;pre&gt;  &quot;dependencies&quot;: {

    ...

    &quot;azure&quot;: &quot;*&quot;

  }

&lt;/pre&gt;

&lt;p&gt;Then let NPM install the module:&lt;/p&gt;

&lt;pre&gt;npm install&lt;/pre&gt;

&lt;p&gt;Now we can easily work with the Queue service. First initialize a &lt;em&gt;&amp;#8216;request&amp;#8217;&lt;/em&gt; queue in your &lt;em&gt;app.coffee&lt;/em&gt;:&lt;/p&gt;

&lt;pre&gt;# Get the queue service&lt;br/&gt;cloud = require &apos;azure&apos;&lt;br/&gt;queue = cloud.createQueueService()&lt;br/&gt;&lt;br/&gt;# Ensure the queue exists&lt;br/&gt;queue.createQueueIfNotExists &apos;request&apos;, (error) -&amp;gt;&lt;br/&gt;  return unless error&lt;br/&gt;  console.log &quot;Failed to create queue&quot;, error&lt;/pre&gt;

&lt;p&gt;Then start sending information on new requests to the queue by creating a new Express middleware:&lt;/p&gt;

&lt;pre&gt;# Send URL of each request to queue&lt;br/&gt;app.use (req, res, next) -&amp;gt;&lt;br/&gt;  queue.createMessage &apos;request&apos;, req.url, (error) -&amp;gt;&lt;br/&gt;    return unless error&lt;br/&gt;    console.log &quot;Error sending&quot;, error&lt;br/&gt;  do next&lt;/pre&gt;

&lt;h3&gt;Creating a worker&lt;/h3&gt;

&lt;p&gt;Then we just need to create a worker. It can be initialized using the a PowerShell command:&lt;/p&gt;

&lt;pre&gt;C:\node\testapp&amp;gt; Add-AzureNodeWorkerRole queue&lt;/pre&gt;

&lt;p&gt;Now go to the created &lt;em&gt;queue&lt;/em&gt; directory, and add a &lt;em&gt;package.json&lt;/em&gt;:&lt;/p&gt;

&lt;pre&gt;{&lt;br/&gt;  &quot;name&quot;: &quot;test-queue&quot;,&lt;br/&gt;  &quot;version&quot;: &quot;0.0.1&quot;,&lt;br/&gt;  &quot;dependencies&quot;: {&lt;br/&gt;    &quot;coffee-script&quot;: &quot;*&quot;,&lt;br/&gt;    &quot;azure&quot;: &quot;*&quot;&lt;br/&gt;  }&lt;br/&gt;}&lt;/pre&gt;

&lt;p&gt;Again we&amp;#8217;re going to make the actual heavy lifting in CoffeeScript, so change your worker&amp;#8217;s &lt;em&gt;server.js&lt;/em&gt; to say:&lt;/p&gt;

&lt;pre&gt;var coffee = require(&apos;coffee-script&apos;);&lt;br/&gt;var worker = require(&apos;./worker.coffee&apos;);&lt;/pre&gt;

&lt;p&gt;Then edit &lt;em&gt;worker.coffee&lt;/em&gt; and add the following:&lt;/p&gt;

&lt;pre&gt;cloud = require &apos;azure&apos;&lt;br/&gt;queue = cloud.createQueueService()&lt;br/&gt;&lt;br/&gt;# Function that receives new requests from queue and outputs them&lt;br/&gt;checkQueue = -&amp;gt;&lt;br/&gt;  queue.getMessages &apos;request&apos;, (error, messages) -&amp;gt;&lt;br/&gt;    return if error&lt;br/&gt;&lt;br/&gt;    for message in messages&lt;br/&gt;      console.log message&lt;br/&gt;&lt;br/&gt;      # Destroy the message after we&apos;ve caught it&lt;br/&gt;      queue.deleteMessage &apos;request&apos;, message.messageid, message.popreceipt, (error) -&amp;gt;&lt;br/&gt;        return if error&lt;br/&gt;        console.log &quot;Message #{message.messageid} deleted from queue&quot;&lt;br/&gt;&lt;br/&gt;# Poll queue every 0.2 secs&lt;br/&gt;console.log &quot;Setting up queue polling&quot;&lt;br/&gt;setInterval checkQueue, 200&lt;/pre&gt;

&lt;p&gt;If you deploy now, you should have both a worker and a web server available. In the Azure Emulator you can see all web requests getting logged by the worker.&lt;/p&gt;

&lt;h3&gt;About pricing&lt;/h3&gt;

&lt;p&gt;Azure has an &lt;a href=&quot;https://www.windowsazure.com/en-us/pricing/calculator/advanced/&quot;&gt;interesting pricing model&lt;/a&gt;: every running instance costs, and then for storage you have to pay for both the amount of data used, and per transaction.&lt;/p&gt;

&lt;p&gt;The polling worker alone, without any requests to the server, would cost 148.50$ per month. Add to that two web front-ends, and say 400 requests per day and you&amp;#8217;d be at 208.63$ per month.&lt;/p&gt;
</description>
      <pubDate>Fri, 16 Dec 2011 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2F14303346830%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/14303346830/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/14303346830/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>NoFlo - Managing workflows with JavaScript</title>
      <description>&lt;iframe src=&quot;https://player.vimeo.com/video/33288036&quot; width=&quot;400&quot; height=&quot;300&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;&lt;p&gt;My presentation from the &lt;a href=&quot;http://wakanday.org/&quot;&gt;Boston JS.Everywhere&lt;/a&gt; conference.&lt;/p&gt;

&lt;p&gt;The slides are &lt;a href=&quot;http://www.slideshare.net/bergie/noflo-flowbased-programming-for-nodejs&quot;&gt;also available&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Sat, 10 Dec 2011 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2F14021122301%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/14021122301/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/14021122301/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
    <item>
      
      <title>Node.js for Java developers</title>
      <description>&lt;a href=&quot;http://www.ibm.com/developerworks/java/library/j-nodejs/index.html&quot;&gt;Node.js for Java developers&lt;/a&gt;
</description>
      <pubDate>Tue, 06 Dec 2011 00:00:00 +0000</pubDate>
      <atom:link rel="payment" href="https://flattr.com/submit/auto?url=https%3A%2F%2Fbergie.iki.fi%2Fblog%2F13840380930%2F&amp;user_id=bergie" type="text/html" />
      <link>https://bergie.iki.fi/blog/13840380930/</link>
      <guid isPermaLink="true">https://bergie.iki.fi/blog/13840380930/</guid>
      <author>henri.bergius@iki.fi (Henri Bergius)</author>
    </item>
    
  </channel>
</rss>
