ActionHero is a multi-transport Node.JS API Server with integrated cluster capabilities and delayed tasks.
In ActionHero, you make actions which respond to client requests.
{% highlight javascript %} // actionhero generate action --name=randomNumber // File: actions/randomNumber.js exports.randomNumber = { name: 'randomNumber', description: 'I am an API method which will generate a random number', outputExample: { randomNumber: 0.123 }, run: function(api, data, next){ data.response.randomNumber = Math.random(); next(); } }; {% endhighlight %}These actions don't just work for the web, they work for all sorts of clients!
ActionHero also lets you perform tasks in the background...
{% highlight javascript %} // actionhero generate action --name=sendEmail // File: tasks/sendEmail.js exports.task = { name: 'sendEmail', description: 'send an email to users after they sign up' queue: 'default', frequency: 0, run: function(api, params, next){ // email sending stub api.users.sendEmail(params.userId, function(error, done){ next(error); }); }); }; {% endhighlight %}... and you can invoke the task from anywhere in the framework, including actions.
{% highlight javascript %} // api.tasks.enqueue(nameOfTask, args, queue, callback) api.tasks.enqueue("sendEmail", {to: 'evan@evantahler.com'}, 'default', function(error, toRun){ // enqueued! }); {% endhighlight %}ActionHero enables clients to talk to each other.
{% highlight javascript %} // client 1 var client1 = new ActionheroClient; client1.connect(function(error, details){ client1.roomAdd("myChatRoom", function(error){ client1.say('myChatRoom', 'hello from client 1'); }); }); // client 2 var client2 = new ActionheroClient; client2.connect(function(error, details){ client2.roomAdd("myChatRoom", function(error){ client2.on('say', function(message){ console.log(message); }); }); }); {% endhighlight %}ActionHero can do all of this, and it can work on one server or hundreds (ActionHero is cluster-ready from the get-go).
{% highlight bash %} # start 1 instance ./node_modules/.bin/actionhero start # start a cluster ./node_modules/.bin/actionhero start cluster {% endhighlight %}