Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Simple Actor Model implementation. It wraps any Javascript object as an actor.
Branch: master


Simple Actor Model implementation.

See Actor Model in Wikipedia.


This implementation is inspired in Akka actor implementation.

This model encourage the writing of application consisting in actors that collaborates using message passing. In this module, method invocation is like a message passing operation, that not returns value. The application that uses actor model doesn't need continuation callbacks: each agent receives messages as method invocation, and produces new messages calling other agent methods.


Via npm on Node:

npm install simpleactors

Reference in your program:

var simpleactors = require('simpleactors');


Create a system application:

var system = simpleactors.create('webcrawler');

Create an object of class Downloader, wrap it as an actor, and returns an actor reference:

var ref = system.actorOf(Downloader, 'downloader');

Alternatively, you can use an already create object as first parameter:

var downloader = new Downloader();
var ref = system.actorOf(downloader, 'downloader');

The second parameter is optional. A name is automatically assigned if the second parameter is missing.

Sends a message to an actor reference:


An object wrapped as an actor has:

  • context: Actor context, with information about the actor environment.
  • self: This actor reference.

It should implement the function:

  • receive(msg): Process an incoming message


function Logger() {
    this.receive = function (msg) {

var system = simpleactors.create('mysys');
var ref = system.actorOf(Logger);
ref.tell('Hello, world');

How to create an actor in our actor object:

this.context.actorOf(MyActor, name);

How to get an actor reference in our actor object:

var ref = this.context.actorFor(path);


var refchild = this.context.actorFor('mychild'); // child of current actor
var refactor = this.context.actorFor('/myroot/myactor'); // actor in current system

How to get an actor reference in a system:

var ref = system.actorFor(path);


var ref = system.actorFor('/myroot/myactor'); // actor in current system

An actor system can run in many nodes (running process).

var node = simpleactors.createNode(port [, host]);

Example creating a node, a system, and two actors:

var node = simpleactors.createNode(3000);
var system = node.create('mysys');
var actor1 = system.actorOf(MyActor, 'actor1');
var actor2 = actor1.context.actorOf(MyActor, 'actor2');
// actor1.self.path === 'sactors://mysys@localhost:3000/actor1'
// actor2.self.path === 'sactors://mysys@localhost:3000/actor1/actor2'

A node can refer to another running node. In node A:

var node = simpleactors.createNode(3000);
var system = node.create('mysys');
var actor1 = system.actorOf(MyActor, 'actor1');

In node B:

var node = simpleactors.createNode(3001);
var remotenode = node.createRemoteNode(3000);
var remotesystem = remotenode.create('mysys');
var remoteref = remotesystem.actorFor('/actor1');
remotenode.start(function () {
    // after connection, you can tell messages to remote actors


git clone git://
cd SimpleActors
npm install
npm test


Web Crawler sample shows how you can create an application that don't depend on calling a method and receiving a response: each agent does its works, receiving calls and sending calls to other agents.

Distributed Web Crawler sample has a server that launch the web crawling process, and many clients can be launched that collaborates with the download and harvest of new links to process. It uses a custom router.


  • 0.0.1: Published
  • 0.0.2: Under development, in master.



Feel free to file issues and submit pull requests — contributions are welcome.

If you submit a pull request, please be sure to add or update corresponding test cases, and ensure that npm test continues to pass.

(Thanks to JSON5 by aseemk. This file is based on that project

Something went wrong with that request. Please try again.