# arrowdb

> Appcelerator ArrowDB SDK for NodeJS

Latest version **1.0.12** (published 2019-08-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install arrowdb
pnpm add arrowdb
yarn add arrowdb
bun add arrowdb
```

## 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.12 |
| Published | 2019-08-21 |
| First published | 2015-02-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 4 |
| Unpacked size | 141 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | Appcelerator, Inc. |
| Maintainers | appcelerator, baobeimm |
| Keywords | appcelerator, arrowdb |

## Links

- npm: https://www.npmjs.com/package/arrowdb
- Repository: https://github.com/appcelerator/arrowdb-node-sdk
- Homepage: https://github.com/appcelerator/arrowdb-node-sdk#readme
- Issues: https://github.com/appcelerator/arrowdb-node-sdk/issues
- npm.io page: https://npm.io/package/arrowdb

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^2.1.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [request](https://npm.io/package/request.md) ^2.55.0
- [tough-cookie](https://npm.io/package/tough-cookie.md) ^2.3.0

## Recent versions

- 1.0.12 (latest) — 2019-08-21
- 1.0.11 — 2017-02-13
- 1.0.10 — 2016-09-22
- 1.0.9 — 2016-05-24
- 1.0.8 — 2016-03-10
- 1.0.7 — 2015-07-07
- 1.0.6 — 2015-04-19
- 1.0.5 — 2015-04-15
- 1.0.4 — 2015-03-20
- 1.0.3 — 2015-03-20
- 1.0.2 — 2015-03-07
- 1.0.1 — 2015-03-07
- 1.0.0 — 2015-02-10

## README

# ArrowDB Node SDK [![Build Status](https://travis-ci.org/appcelerator/arrowdb-node-sdk.svg)](https://travis-ci.org/appcelerator/arrowdb-node-sdk)

The SDK of ArrowDB for NodeJS

## Getting started

```bash
git clone git+https://github.com/appcelerator/arrowdb-node-sdk.git
cd arrowdb-node-sdk
npm install
```

## Basic Example

You can get an overview of ArrowDB Node SDK example from examples/basic.js

```bash
cd arrowdb-node-sdk/examples
export ARROWDB_APPKEY=YOUR_ARROWDB_TEST_APPKEY
node basic.js
```

## ArrowDB Node SDK Example on Node.ACS
There is another example for ArrowDB Node SDK to show how to run on Node.ACS as a service.

Make sure you have installed Node.ACS command line tool first:

```bash
sudo npm -g install acs
```

Then you can try:

```bash
cd arrowdb-node-sdk/examples/over_nodeacs
# Update config.json to fill in your ArrowDB app key
vi config.json
acs run
```

Open another session and try:

```bash
curl -b cookie.txt -c cookie.txt -X POST -F "login=YOUR_USERNAME" -F "password=YOUR_PASSWORD" http://localhost:8080/login
curl -b cookie.txt -c cookie.txt -X GET http://localhost:8080/showMe
```

# ArrowDB Node SDK Basic Usage

## Use ArrowDB Node SDK directly

```javascript
var ArrowDB = require('arrowdb');
var arrowDBApp = new ArrowDB('Your_ARROWDB_APPKEY');

arrowDBApp.usersLogin({
    login: ARROWDB_USERNAME,
    password: ARROWDB_PASSWORD
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    console.log('Logged in user: %j', result.body);
    arrowDBApp.usersShowMe(function(err, result) {
        if (err) {
            console.error(err);
            return;
        }
        console.log('Show user: %j', result.body);
    });
});
```

## Use ArrowDB Node SDK inner express or http/https NodeJS module

```javascript
// HTTP call 1 with cookie:
var arrowDBApp = new ArrowDB('Your_ARROWDB_APPKEY');

arrowDBApp.usersLogin({
    login: req.body.login,
    password: req.body.password,
    req: req,
    res: res
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    res.end(result.body);
});

// HTTP call 2 with cookie, after HTTP call 1:
var ArrowDB = require('arrowdb');
var arrowDBApp = new ArrowDB('Your_ARROWDB_APPKEY');

arrowDBApp.usersShowMe(ARROWDB_APPKEY, {
    req: req,
    res: res
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    res.end(result.body);
});
```

## Custom ACS Endpoint

```javascript
var ArrowDB = require('arrowdb');
var arrowDBApp = new ArrowDB(arrowDBKey, {
	    apiEntryPoint: "api.customacs.com",
		prettyJson: true
	});
```

## General RestAPI call

```javascript
var arrowDBApp = new ArrowDB('Your_ARROWDB_APPKEY');

arrowDBApp.post(ARROWDB_APPKEY, '/v1/users/login.json', {
    login: ARROWDB_USERNAME,
    password: ARROWDB_PASSWORD
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }

    console.log('ArrowDB returned body: %j', result.body);
    console.log('Cookie string returned: %s', result.cookieString);

    arrowDBApp.get(ARROWDB_APPKEY, '/v1/users/show/me.json', function(err, result) {
        if (err) {
            console.error(err);
            return;
        }
        console.log('ArrowDB returned user: %j', result.body);
    });
});
```

## Session Management

By default, arrowdb-node-sdk will manage sessions for you automatically when you
log in and out. You can create a new `ArrowDB` instance for each authenticated
session. You can also reuse an existing instance by calling `usersLogin()` again,
however this simply overwrites the existing session cookie and will not log out
the previous session.

However, if you'd prefer to manually manage the session cookie, then you can set
the `autoSessionManagement` option to `false` when the `ArrowDB` instance is
created.

```javascript
var arrowDBApp = new ArrowDB('Your_ARROWDB_APPKEY', {
    autoSessionManagement: false
});
```

This means once you log in, you must track the session cookie yourself:

```javascript
arrowDBApp.usersLogin({
    login: ARROWDB_USERNAME,
    password: ARROWDB_PASSWORD
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    
    console.log('Logged in user');
    console.log('Cookie string returned: %s', result.cookieString);
    
    // IMPORTANT! You must set the sessionCookieString or else all privileged calls will fail
    arrowDBApp.sessionCookieString = result.cookieString;
});
```

## Running Unit Tests

To run the unit tests, simply run:

    export ARROWDB_APPKEY=ONE_OF_YOUR_ARROWDB_TEST_APPKEY
    npm test

## License

This project is open source and provided under the Apache Public License
(version 2). Please make sure you see the `LICENSE` file included in this
distribution for more details on the license.  Also, please take notice of the
privacy notice at the end of the file.

#### (C) Copyright 2015, [Appcelerator](http://www.appcelerator.com/) Inc. All Rights Reserved.

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