Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
174 lines (127 sloc) 5.42 KB

Flux - A Haxe Stack for Node.js

Formerly cloudshift, name changed due to clash with an existing cloud product.

See documentation here

Flux is written and maintained by Ritchie Turner ( and is currently under heavy development; the apis are subject to change.

Flux hides the Node.js api, and attempts to be a general comprehensive stack for async programming in Haxe, so that as other async libraries appear Node.js could be swapped out. In the short term, Node.js is the first choice platform.

Core Module

Flux provides a consistent set of abstractions on client and server for dealing with common problems:

  • Asynchronous haXe remoting for inter tier and sub-process communication
  • Outcome<A,B> (a Future<Either<A,B>>) as the means for dealing with async callback hell and error handling with helper functions provided as Mixins.
  • Mixins, mostly the Stax prelude extensions.
  • Observables - Typical observer functionality.

Http Module

Simplest example …


and/or provide multiple handlers per url, e.g.


For haXers a limited Neko api is also supported on handler req/resp objects to get you going.

Channel Module

Publish/subscribe with session management, channel security. Currently a Push implementation.

  .outcome(function(http) {
        .outcome(function(sess:SessionMgr) {

Once you have your client or server, you may get a channel and pub/sub

function startRooms(channelServer:ChannelServer) {"/chat/room").outcome(function(room) {"blah");
    room.sub(function(msg) {

Data Module

There is a database component with, so far, one driver, Sqlite3. The api is asynchronous and NoSQL where objects are stored in “buckets”. JSON is the default storage format but you may add serializers per bucket if you prefer to store haXe serialized objects or anything else.

Data provides a general indexing facility which utilises the underlying sqlite indexes. Objects are relatable and queryable across buckets.

The Sqlite driver is a popular C++ module for Node.js supported by many of the leading names in the Node.js community. It’s asynchronous and embedded in the node.js instance.

So, each Flux instance has it’s own database, this can be easily augmented so that each instance running talks to a central Flux instance just running data services. Flux provides a remote api compatible driver for this purpose."http://localhost:8082/data")).outcome(function(store) {
store.bucket("woot").outcome(function(woot) {
    woot.where('name="lore"').outcome(function(recs) {
    woot.insert({email:"",name:"lore",passwd:"and why not"})
      .outcome(function(u) {
          trace("lore's id = "+Data.oid(u));

Data also supplies a persistent hash.

The main point here is to think of the Node.js/Sqlite3 combination as a database server in it’s own right

Worker Module

Extend Worker and create seamless sub process workers using the haXe remoting protocol.

Sys Module

File I/O, Process services wrapped in Outcomes as appropriate for this kind of usage:

Sys.writeFile("woot","hi there")
  .oflatMap(function(file) {
        return file.stat();
  .omap(function(stat) {
      return stat.path;
  .oflatMap(function(path) {
      return path.rename("niceone");
  .outcome(function(newFileName) {
      trace("cool "+newFileName);
      var p =;
      p.observe(function(o) {
          switch(o) {
          case ProcessUncaughtException(ex):
            trace("uuncauthg exp:"+ex);

      trace("osuptime:"+Sys.osUptime()+", uptime:"+Sys.uptime());

Installation and Dependencies

install node.js for your platform

  • npm install formidable
  • npm install sqlite3
  • haxelib install nodejs
  • haxelib install flux

Note, the outflux haxelib does not include the nodejs dependency by default, as the outflux lib is used on both client and server having the -D nodejs defined automatically on the client is an unwanted side effect. So be sure to install nodejs bindings manually.

Jump to Line
Something went wrong with that request. Please try again.