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

ccurl

v1.0.0

Published

CouchDB command-line helper

Downloads

86

Readme

ccurl - 'couchdb curl'

If you use CouchDB, then you can access everything using curl. The trouble is that it if you are using an authenticated, hosted service such as Cloudant's, then your credentials appear on your command-line history and there is a lot of typing. e.g.

  curl 'https://mypassword:[email protected]/database/12345678'

With ccurl, this becomes:

  ccurl /database/12345678

Or adding a document with curl:

  curl -X POST -H 'Content-type:application/json' -d'{"a":1,"b":2}' 'https://mypassword:[email protected]/database' 

With ccurl, this becomes:

  ccurl -X POST -d'{"a":1,"b":2}' /database 

Installing

ccurl requires Node.js (and npm). Simply type:

  npm install -g ccurl

Storing your credentials

Your CouchDB credentials are taken from an environment variable "COUCH_URL". This can be set in your console with

  export COUCH_URL="https://mypassword:[email protected]"

or this line can be added to your "~/.bashrc" or "~/.bash_profile" file.

If you don't want credentials stored in your command-line history, you can set an environment variable by extracting the credentials from a file e.g.

export COUCH_URL=`cat ~/.ibm/cloudant.json | jq -r .url`

where ~/.ibm/cloudant.json is a JSON file that is readable only by my user containing the Cloudant service credentials.

Using IBM IAM Authentication

If you prefer to use IBM's IAM authentication for a Cloudant service set up two environment variables:

  • COUCH_URL - the URL of your Cloudant service e.g. https://myurl.cloudant.com (note the absence of authentication credentials).
  • IAM_API_KEY - the IBM IAM API key that identifies you.

ccurl exchanges your API key for a "bearer token" which is automatically inserted into the request. ccurl keeps a cache of the bearer token for subsequent requests. It's stored in ~/.ccurl.

Using ccurl

  • all command-line switches are passed through to curl
  • instead of passing through a full url, pass through a relative url
  • if the url is omitted, then a relative url of "/" is assumed
  • the content-type of 'application-json' is added for you if you don't already provide a content type

Examples

Add a database

  > ccurl -X PUT /newdatabase
  {"ok":true}

Add a document

  > ccurl -X POST -d'{"a":1,"b":2}' /newdatabase 
  {"ok":true,"id":"005fa466b4f690ccad7b4d194f071bbe","rev":"1-25f9b97d75a648d1fcd23f0a73d2776e"}

Get a document

  > ccurl /newdatabase/005fa466b4f690ccad7b4d194f071bbe
  {"_id":"005fa466b4f690ccad7b4d194f071bbe","_rev":"1-25f9b97d75a648d1fcd23f0a73d2776e","a":1,"b":2}

Get ten documents

  > ccurl '/newdatabase/_all_docs?limit=10&include_docs=true' 
  {"total_rows":1,"offset":0,"rows":[{"id":"005fa466b4f690ccad7b4d194f071bbe","key":"005fa466b4f690ccad7b4d194f071bbe","value":{"rev":"1-25f9b97d75a648d1fcd23f0a73d2776e"},"doc":{"_id":"005fa466b4f690ccad7b4d194f071bbe","_rev":"1-25f9b97d75a648d1fcd23f0a73d2776e","a":1,"b":2}}]}

Remove a database

  > ccurl -X DELETE /newdatabase
  {"ok":true}

Other curl command-line parameters work too

  ccurl -h
  ccurl -v
  etc. 

Using ccurl with jq

If jq is installed, ccurl automatically pipes the curl output to jq ., when stdout is a terminal. You may also do the piping yourself to extract a subset of the rdata e.g

 ccurl '/newdatabase/_all_docs?limit=10&include_docs=true' | jq '.total_rows'

or

 ccurl '/newdatabase/_all_docs?limit=10&include_docs=true' | jq '.rows[0].doc.name | length'