The client is responsible for creating a job to be run and sending it to a job server. The job server will find a suitable worker that can run the job and forwards the job on.
-- Gearman Documentation --

Instance of class Client must be created to connect a Gearman job server(s) and to make requests to perform some function on provided data.

var gearmanode =require('gearmanode');

var client =gearmanode.client();

By default, the job server is expected on localhost:4730. Following options can be used for detailed configuration of the client:

Client submits job to a Gearman server and futher processed by a worker via client#submitJob(name, payload, options)
where name is name of registered function a worker is to execute, payload is data to be processed
and options are additional options as follows:

background {boolean} flag whether the job should be processed in background/asynchronous

priority {'HIGH'|'NORMAL'|'LOW'} priority in job server queue

encoding - {string} encoding if string data used, DEPRECATED: ignored, will be removed in next release, use Buffer with corresponding string encoding as payload

unique {string} unique identifiter for the job

toStringEncoding {string} if given received response will be converted to String with this encoding, otherwise payload turned over as Buffer

A function the worker is able to perform can be registered via worker#addFunction(name, callback, options)
where name is a symbolic name of the function, callback is a function to be run when a job will be received
and options are additional options as follows:

timeout {number} timeout value in seconds on how long the job is allowed to run, thereafter the job server will mark the job as failed and notify any listening clients

toStringEncoding {string} if given received payload will be converted to String with this encoding, otherwise payload turned over as Buffer

The Job object is an encapsulation of job's attributes and interface for next communication with job server.
Additionally is the object en emitter of events corresponding to job's life cycle (see Job events).

The job has following getters

name - name of the function, [Client/Worker]

payload - transmited/received data (Buffer or String) [Client/Worker]

response - data that is returned to the client as a response if job is done by a worker [Client]

Both binary data and text with various encoding are supported. By default the data delivered to client and worker are Buffer objects.
You can change this approach by providing toStringEncoding option in Client#submitJob or Worker#addFunction.
See following snippets of code or test-all-stack.js for more inspiration.

// send text with default encoding; Job#response will be a Buffer object

client.submitJob('reverse','123');

// send text with given encoding; Job#response will be a Buffer object

client.submitJob('reverse',Buffer('123','ascii').toString());

// send text with given encoding; Job#response will be a String object with ASCII encoding

client.submitJob('reverse','123',{toStringEncoding:'ascii'});

// and receive text on Worker; Job#payload will be a String object with ASCII encoding

Although exceptions are supported in JavaScript and they can be used to communicate an error, due to asynchronous concept of Node.js it can be a bad idea.
According to Node.js best practices following error handling is introduced in GearmaNode.

In asynchronous code an error event will be emitted via EventEmitter on corresponding object if something goes wrong.
This happens mostly by network communication failure or if a gearman service fails.