# couch-profile

> Store profile information in couchdb

Latest version **1.0.16** (published 2013-03-17) · BSD license · 0 weekly downloads

## Install

```sh
npm install couch-profile
pnpm add couch-profile
yarn add couch-profile
bun add couch-profile
```

## Health

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

Positive: no vulnerabilities.

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

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.16 |
| Published | 2013-03-17 |
| First published | 2013-02-20 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Noah Isaacson |
| Maintainers | clewfirst |
| Keywords | couchdb, couchdb-update-views, cradle, user, profile, profiles, browserid |

## Links

- npm: https://www.npmjs.com/package/couch-profile
- Repository: https://github.com/nisaacson/couch-profile
- npm.io page: https://npm.io/package/couch-profile

## Dependencies (4)

- [cradle](https://npm.io/package/cradle.md) ~0.6.4
- [eyespect](https://npm.io/package/eyespect.md) ~0.1.8
- [bcrypt-nodejs](https://npm.io/package/bcrypt-nodejs.md) git://github.com/nisaacson/bcrypt-nodejs.git
- [required-keys](https://npm.io/package/required-keys.md) ~1.0.4

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.16 (latest) — 2013-03-17
- 1.0.15 — 2013-03-02
- 1.0.14 — 2013-03-02
- 1.0.13 — 2013-03-02
- 1.0.11 — 2013-02-27
- 1.0.10 — 2013-02-27
- 1.0.9 — 2013-02-27
- 1.0.8 — 2013-02-27
- 1.0.7 — 2013-02-20
- 1.0.6 — 2013-02-20
- 1.0.5 — 2013-02-20
- 1.0.4 — 2013-02-20
- 1.0.3 — 2013-02-20
- 1.0.2 — 2013-02-20
- 1.0.1 — 2013-02-20
- … 1 more at https://npm.io/package/couch-profile/versions

## README

Store profile information in couchdb

[![Build Status](https://travis-ci.org/nisaacson/couch-profile.png)](https://travis-ci.org/nisaacson/couch-profile)
[![Dependency Status](https://david-dm.org/nisaacson/couch-profile/status.png)](https://david-dm.org/nisaacson/couch-profile)
Dependency tracking by [David](https://david-dm.org/)


# Installation
```bash
npm install couch-profile
```

# Usage
To use the module you will first need to setup a [cradle](https://github.com/cloudhead/cradle) connection. A few views are needed in your database to use couch profiles. Look in the <project_roo>/docs/ folder to see the views needed. You can easily create these view using the [couchdb-update-views](https://github.com/nisaacson/couchdb-update-views)

## API
Look at index.js to see the full public api available. The following functions are available for use

- findProfile
- getOrCreateProfile
- checkPassword
- hashPassword

## Instatiate Views
```bash
npm install -g couchdb-update-views
couchdb-update-views --config <path/to/config.json> --docsDir <couch-profile_project_root>/docs
```


## Get Or Create Profile
This will automatically create a new profile if needed. Use **findProfile** if you just want to lookup a profile without creating one
```javascript
var couchProfile = require('couch-profile')
var db = <cradle database connection>
var profileData = {
  db: db,
  email: 'foo@example.com',
  password: 'barPass' // this will be salted and hashed before storage
}
couchProfile.getOrCreateProfile(profileData, function(err, profile) {
  if (err) {
    inspect(err, 'error getting profile')
    return
  }
  inspect(profile, 'got couch profile')
})
```


## Find Profile
Lookup a profile but don't create new ones
```javascript
var couchProfile = require('couch-profile')
var db = <cradle database connection>
var profileData = {
  db: db,
  email: 'foo@example.com'
}
couchProfile.getProfile(profileData, function(err, profile) {
  if (err) {
    inspect(err, 'error getting profile')
    return
  }
  inspect(profile, 'got couch profile')
})
```


## Passwords
If you create a profile with a **password** field, it will be salted and hashed and stored in a hash field. The actual password value is not stored. Hashing is done with the native nodejs bcrypt implementation [https://github.com/shaneGirish/bcrypt-nodejs](https://github.com/shaneGirish/bcrypt-nodejs)

```javascript
var bcrypt = require('bcrypt-nodejs')
var couchProfile = require('couch-profile')
var password = 'fooBarPass'
couchProfile.hashPassword(profileData, function(err, profile) {
  if (err) {
    inspect(err, 'error hashing password')
    return
  }
  inspect(password, 'original raw password')
  inspect(reply, 'hashed password')
  bcrypt.compare(password, hash, function (err, reply) {
    if (err) {
      inspect(err, 'erorr checking if hashed password matches')
      return
    }
    inspect(reply, 'does hash check out? ')
  })
})
```

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