Socket
Socket
Sign inDemoInstall

couchdb-request

Package Overview
Dependencies
49
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    couchdb-request

Minimilist couchdb client on top of request.


Version published
Weekly downloads
4
increased by300%
Maintainers
1
Install size
3.77 MB
Created
Weekly downloads
 

Readme

Source

couchdb-request

Build Status

Minimalist couchdb client on top of request. Unlike other couchdb-client, this module expose the powerful request object to enable chaining. This make it easy to use it as a proxy between client (browser) and couchDB server.

This in turn allows us to do additional action like sending email confirmation after user successfully register or add additional check at the login form to rate limit login attempt.

##Install

$npm install couchdb-request

##Method

API

All method is basically a very light request abstraction and every call will return the same request object. All method from request module is available. Please refer the CouchDB API documentation at docs.couchdb.org for available REST API.

configuration
const couchdb = require('couchdb-request')(opts)

This api should be called first to set the correct database parameter before calling any database action method.

database(url)

Database name to query to

  • database name eg: booking
get(id, [callback])

Get database value

  • id document id
  • callback (optional) function to execute after request complete
put(id, data, [callback])

Insert data to database

  • id document id
  • data (json) object data to save
  • callback (optional) function to execute after request complete
post(id, data, [callback])

Insert data to database

  • id document id
  • data (json) object data to save
  • callback (optional) function to execute after request complete
del(id, callback)

Delete data from database

  • id document id
  • data (json) object to save
  • callback function to execute after request complete
save(id, data, callback)

Update existing data. This api will automatically get the latest rev to use for updating the data.

  • id document id
  • data (json) object to save
  • callback function to execute after request complete
view(design, opts, [callback])

Query rows of data using views

  • id view id
  • opts (json) options parameter as documented here
  • callback (optional) function to execute after request complete

##Usage example

const bodyParser = require('body-parser');
const express    = require('express');
const couchdb    = require('couchdb-request')('https://admin:password@localhost:5984');
    
var app = express();
app.use(bodyParser.json());

app.post('/register', (req, res) => {
  couchdb
  .database('_users') //select database
  .put('org.couchdb.user:' + req.body.email, req.body) //method
  .on('error', err => console.log(err)) //log on error
  .on('response', result => sendEmailConfirmation(req.body)) //send email on success
  .pipe(res) //stream to browser
      
})

app.listen(3000);

Using callback function

couchdb
.database('_users')
.get('org.couchdb.user:myuser@hello.com', res => {
  console.log(res);
})

Reference

Keywords

FAQs

Last updated on 26 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc