$ npm install space-engine-node --save
const Engine = require('space-engine-node');
const engine = new Engine('my-engine');
Note: All instances with same engine name are automatically load balanced.
engine.registerFunc('my-func', (params, auth, cb) => {
console.log('Params:', params, 'Auth', auth)
// Do something
const res = { ack: true, message: 'Function as a Service is Awesome!' }
cb('response', res)
})
Note: Enable Functions module in Space Cloud, run space-exec and nats server to be able to use it.
- Engine
Class representing the Engine Interface.
- Callback(type, res)
Callback to be called before returning from function.
- EngineFunction(params, auth, cb)
Callback for realtime updates to the subscribed data
Class representing the Engine Interface.
Kind: global class
Create an instance of the Engine API.
Param | Type | Description |
---|---|---|
engineName | string |
Name of the engine. |
opts | string | Object |
Connection options for Nats. |
Example
const Engine = require('space-engine-node');
const engine = new Engine('my-engine');
// Register function with engine
engine.registerFunc('my-func', (params, auth, cb) => {
console.log('Params:', params, 'Auth', auth)
// Do something
const res = { ack: true, message: 'Function as a Service is Awesome!' }
cb('response', res)
})
Register the function to FaaS Engine
Kind: instance method of Engine
Param | Type | Description |
---|---|---|
name | string |
Name of the function. |
func | EngineFunction |
Function to be registered |
Callback to be called before returning from function.
Kind: global function
Param | Type | Description |
---|---|---|
type | string |
Type of callback action to be performed. |
res | Object |
Data to be sent to client. |
Callback for realtime updates to the subscribed data
Kind: global function
Param | Type | Description |
---|---|---|
params | Object |
Params received by function. |
auth | Object |
Auth object of client. Will be undefined if request is unauthenticated. |
cb | Callback |
The callback function to be called by the function. |