# space-engine-node

> Function as a Service engine API for Space Cloud in node

Latest version **1.0.2** (published 2018-08-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install space-engine-node
pnpm add space-engine-node
yarn add space-engine-node
bun add space-engine-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-08-23 |
| First published | 2018-08-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Noorain Panjwani |
| Maintainers | noorainp |

## Links

- npm: https://www.npmjs.com/package/space-engine-node
- npm.io page: https://npm.io/package/space-engine-node

## Dependencies (2)

- [nats](https://npm.io/package/nats.md) ^1.0.1
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.2.0

## Recent versions

- 1.0.2 (latest) — 2018-08-23
- 1.0.1 — 2018-08-23
- 1.0.0 — 2018-08-22

## README

# Client API for Space Cloud

## Installation

```bash
$ npm install space-engine-node --save
```

## Quick Start

### Create Engine Instance

```js
const Engine = require('space-engine-node');

const engine = new Engine('my-engine');
```

**Note: All instances with same engine name are automatically load balanced.**

### Register the function 
```js
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.**

## Classes

<dl>
<dt><a href="#Engine">Engine</a></dt>
<dd><p>Class representing the Engine Interface.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#Callback">Callback(type, res)</a></dt>
<dd><p>Callback to be called before returning from function.</p>
</dd>
<dt><a href="#EngineFunction">EngineFunction(params, auth, cb)</a></dt>
<dd><p>Callback for realtime updates to the subscribed data</p>
</dd>
</dl>

<a name="Engine"></a>

## Engine
Class representing the Engine Interface.

**Kind**: global class  

* [Engine](#Engine)
    * [new Engine(engineName, opts)](#new_Engine_new)
    * [.registerFunc(name, func)](#Engine+registerFunc)

<a name="new_Engine_new"></a>

### new Engine(engineName, opts)
Create an instance of the Engine API.


| Param | Type | Description |
| --- | --- | --- |
| engineName | <code>string</code> | Name of the engine. |
| opts | <code>string</code> \| <code>Object</code> | Connection options for Nats. |

**Example**  
```js
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)
})
```
<a name="Engine+registerFunc"></a>

### engine.registerFunc(name, func)
Register the function to FaaS Engine

**Kind**: instance method of [<code>Engine</code>](#Engine)  

| Param | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | Name of the function. |
| func | [<code>EngineFunction</code>](#EngineFunction) | Function to be registered |

<a name="Callback"></a>

## Callback(type, res)
Callback to be called before returning from function.

**Kind**: global function  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of callback action to be performed. |
| res | <code>Object</code> | Data to be sent to client. |

<a name="EngineFunction"></a>

## EngineFunction(params, auth, cb)
Callback for realtime updates to the subscribed data

**Kind**: global function  

| Param | Type | Description |
| --- | --- | --- |
| params | <code>Object</code> | Params received by function. |
| auth | <code>Object</code> | Auth object of client. Will be undefined if request is unauthenticated. |
| cb | [<code>Callback</code>](#Callback) | The callback function to be called by the function. |

---
_Source: https://npm.io/package/space-engine-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
