OrbiterMicroNode Quick Start

To create a basic OrbiterMicroNode application, follow these steps:

Step 1: Install Node.JS

Obtain and install Node.JS from http://nodejs.org/. OrbiterMicroNode has been tested up to Node 0.4.8. For instructions on installing Node.JS or building it from source, see:

For old Node.JS binaries (e.g., 0.4.8), see:

Step 2: Download OrbiterMicroNode

Download the latest build of OrbiterMicroNode here:

http://www.unionplatform.com/staging/releases/orbitermicronode/latest

Step 3: Create Your Application Directory

Create a directory on your file system to contain your application. For this example, name the directory "OrbiterMicroNodeApp".

Step 4: Create the node_modules Directory

Inside the OrbiterMicroNodeApp directory, create a subdirectory named node_modules.

Step 5: Unzip OrbiterMicroNode

Unzip the OrbiterMicroNode .zip file (from Step 1) into the node_modules directory.

Step 6: Create Your Main Application File

In the OrbiterMicroNodeApp directory, create a new file named Main.js.

Step 7: Add OrbiterMicroNode to Your Application

Add the following code to Main.js. Replace OrbiterMicroNodeFolderNameGoesHere with the name of the folder that was created during the unzip process in Step 5.

//==============================================================================
// VARIABLES
//==============================================================================
// The root of the OrbiterMicro object model
var net;
// A reference to this client's Orbiter object
var orbiter;

// Command-line arguments
var host;
var port;

//==============================================================================
// BOOT FUNCTIONS
//==============================================================================
function main () {
  // Quit if command line args don't validate
  var args = process.argv.slice(2);
  if (args.length < 2) {
    usage();
    return;
  }

  out('Booting...');

  // Parse command-line args
  host = args[0];
  port = args[1];

  // Load OrbiterMicroNode module
  net = require('OrbiterMicroNodeFolderNameGoesHere').net;

  // Listen for command-line input
  var stdin = process.openStdin();
  stdin.on('data', onStdInData);

  // Start the client
  init();
}

function usage() {
  out('Usage:');
  out('node Main.js [host] [port]');
  out('Example: node Main.js tryunion.com 80');
  process.exit();
}

//==============================================================================
// INITIALIZATION
//==============================================================================
function init () {
  // Create the Orbiter instance, used to connect to and communicate with Union
  orbiter = new net.user1.orbiter.Orbiter();

  // Register for Orbiter's connection events
  orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.READY, readyListener, this);
  orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.CLOSE, closeListener, this);

  // Connect to Union
  orbiter.connect("tryunion.com", 80);
  out("Connecting to Union...");
}

//==============================================================================
// ORBITER EVENT LISTENERS
//==============================================================================
// Triggered when the connection is ready
function readyListener (e) {
  out("Connected.");
}

// Triggered when the connection is closed
function closeListener (e) {
  out("Orbiter connection closed.");
}

//==============================================================================
// STD IN/OUT
//==============================================================================
function out (msg) {
  console.log(msg);
}

function onStdInData (data) {
  var data = data.toString().trim();
  var cmd = data.split(':')[0];
  var data = data.split(':')[1];
  switch (cmd) {
    case 'q':
      process.exit();
      break;
  }
}

//==============================================================================
// BOOT THE APP
//==============================================================================
main();

Step 8: Add Application Logic

Add your own custom logic in Main.js's readyListener() function, which is triggered when your client connects to Union. In your code, you have full access to the OrbiterMicro API. For examples and an API reference guide, see the OrbiterMicro documentation.

Step 9: Run Your Application

To run your application, issue the following command at your system's command prompt from the OrbiterMicroNodeApp directory:

node Main.js tryunion.com 80

Step 10: Learn By Example

To see the steps in this quick start assembled into a fully functional example, see OrbiterMicroNode Chat Bot example.

Step 11: Get Support

If you have questions or need help, visit the Union Platform forums. For priority support, consider a Union Member licence.