Developing JavaScript Services

Node.js is an event-driven I/O framework for the V8 JavaScript engine, intended for implementing scalable network programs such as web servers and streaming servers. Since Node apps do not require a UI or browser ("DOM" less) -- they run in their own instance of V8 -- they are more related to server-side JavaScript.

Node.js uses an event loop instead of threads, allowing it to scale to potentially millions of concurrent connections. It exploits the fact that servers spend most of their time waiting for I/O operations, which are much slower than in-memory operations. Every I/O operation in Node.js is asynchronous, which allows the server to continue processing incoming requests while I/O takes place in the background. This event-based model makes Node.js very fast, and makes scaling real-time applications very easy. JavaScript is extremely well suited to event-based programming because of its anonymous functions and closures, which make defining inline callbacks very simple.

In addition, the active Node development community provides support and a rapidly growing library of modules that you can use in your webOS services.

Foundations

Services (as well as apps) can take advantage of HP's Foundation libraries of JavaScript utilities. Foundations provides utilites for:

  • Object, string, and array processing
  • AJAX calls
  • Accessing webOS services
  • Asynchronous processing (Futures)
  • Map reduce functionality
  • Implementing Finite State Machines
  • XML and JSON conversion and validation
  • Creating class and error objects

See the Foundations API reference for more information.

Next Steps

To begin understanding how to implement services, you should step through the Creating a Hello World Service procedure. Like all Hello World-type implementations, the intention is to strip the process down to a bare minimum, clearly showing what is involved and establishing a base for further development. Through this procedure, you will learn how to create and package a service, install it on the public bus, and call it from a JavaScript app.

After that, if you are interested in creating a Synergy connector with a JavaScript Synergy service, you can step through the Creating a Synergy Contacts Package tutorial. This will step you through the basics of creating and installing a Synergy app/service/account package, integrating with the webOS Contacts app, implementing a bare-bones Synergy service, and authenticating and syncing with an outside data source, in this case, Plaxo, an online address book and social networking site (www.plaxo.com).

Additional Documentation