npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-couchdb-core

v0.4.0

Published

A core rest api for a couchdb database

Downloads

3

Readme

Express CouchDb Core

This module provides a generic restful api for accessing couchdb documents. By dropping this module in your express application you can immediately start managing couchdb documents via a restful crud interface in your single page application. This module only includes list, create, read, update and delete, it does not include any view or query functionality, this has to be implemented in your express application.

Install

npm install express-couchdb-core --save
// add model design and all view to couchDb
node init.js [couchdb]

Usage

var core = require('express-couchdb-core');
var config = { couch: 'http://localhost:5984/foo' };
app.config(function() {
  // handle other requests first
  app.use(express.router);
  // handle core requests
  app.use(core(config));
});

Optional configuration

If you would like to dynamically change which database is being used, then use the following configuration and set the request parameter given to the name of the database to use. The database_parameter_name is optional and will default to "COUCH_DB".

var config = { url: 'http://localhost:5984', database_parameter_name: 'COUCH_DB'}

API

The api uses the term model to represent the document type, and it is assumed that when you store your documents you will use the type node in the document to represent the model type. For example,

{
  "_id": "123456789",
  "name": "Johnny Paper",
  "type": "person"
}

RESTFul call

GET /api/person

will return all documents of type "person"

GET /api/:model

Returns a list of documents of the type :model

POST /api/:model

Create a document of type :model

GET /api/:model/:id

Returns a couch document

PUT /api/:model/:id

Updates an existing couch document or creates a couch document with specific id

DEL /api/:model/:id

Deletes a couch document

Adding Child docs

This module comes with a feature to add child docs that can also be pulled down with a get request from the parent as an array in the parent node.

For Example:

POST /api/foo

{
  "_id": 1,
  "_rev": 1,
  "name": "bar",
  "type": "foo"
}

Next we post a child document to foo and we use the underscore to indicate it is a child document type and use the [model]_id to assign ownership to the parent document.

POST /api/foo_bar

{
  "_id": 2,
  "_rev": 1,
  "name": "baz",
  "type": "foo_bar",
  "foo_id": 1
}

This will link the document type foo_bar as a child to document type foo. And when you get the foo document of id 1, it will return the foo document with a key called foo_bar: [] and the child document in that array.

GET /api/foo/1

{
  "_id": 1,
  "_rev": 1,
  "name": "bar",
  "type": "foo",
  "foo_bar": [{
    "_id": 2,
    "_rev": 1,
    "name": "baz",
    "type": "foo_bar",
    "foo_id": 1
  }]
}

you can have multiple children docs attached to a parent doc.

License

MIT

Contributions

Pull Requests Welcome