Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/glynnbird/cloudantlib
A proposed Node.js library for Cloudant
https://github.com/glynnbird/cloudantlib
Last synced: 5 days ago
JSON representation
A proposed Node.js library for Cloudant
- Host: GitHub
- URL: https://github.com/glynnbird/cloudantlib
- Owner: glynnbird
- Created: 2015-05-06T10:09:16.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-11T12:09:41.000Z (over 9 years ago)
- Last Synced: 2024-10-12T22:13:13.601Z (about 1 month ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cloudant Node.js Library - PROVISIONAL
This repository is a demonstration of what could be used instead of the existing Cloudant Node.js library. It has the following advantages:
* it is a thing wrapper around Nano (the official CouchDB Node.js library)
* Nano is a direct dependency of this library. If Nano changes, we simply change the dependent version, retest and republish
* it defers to Nano for almost everything; it has the same method of initialsation and returns a Nano object
* if the URL used at configure the library ends in "cloudant.com", we add additional functions that are specifc to Cloudante.g.
# Using the library
```
var cloudant = require('./cloudant.js')("https://MYUSERNAME:[email protected]");
```or
```
var obj = { account: "MYACCOUNT", password: "MYPASSWORD"};
var cloudant = require('./cloudant.js)(obj);
```## Generating a Cloudant API Key
```
// create an API key
cloudant.generate_api_key(function(err, data) {
console.log(data);
});
// { password: 'aPio3N4FSUXbLIcl2gnCjRcM', ok: true, key: 'gewgigbwifmwugw' }
```## Getting the security settings for a database
```
// see who has access to a specific database
var mydb = cloudant.db.use('mydb');
mydb.get_security_(function(err, data) {
console.log(data);
});
// { cloudant: { nobody: [ '_reader' ], myaccount: [ '_reader', '_writer', '_admin', '_replicator' ] } }
```## Setting the security settings for a database
```
// define who has access to a specific database
var permissions = { nobody: [ '_reader' ], myaccount: [ '_reader', '_writer', '_admin', '_replicator' ] };
var mydb = cloudant.db.use('mydb');
mydb.set_security(permissions, function(err, data) {
console.log(data);
});
// { ok: true }
```## Getting the CORS configuration for an account
```
// get CORS configuration
cloudant.get_cors(function(err, data) {
console.log(data);
});
// { enable_cors: true, allow_credentials: true, origins: [ '*' ] }
```## Setting the CORS configuration for an account
```
// set CORS configuration
var configuration = { enable_cors: true, allow_credentials: true, origins: [ '*' ] };
cloudant.set_cors(configuration, function(err,data) {
console.log(err, data)
});
// { ok: true }
```