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 🙏

© 2026 – Pkg Stats / Ryan Hefner

opensrf

v0.4.6

Published

An OpenSRF client library

Readme

NodeJS OpenSRF -- OpenSRF Websockets Client

npm package Build Status

Automate your Evergreen!

OpenSRF is a dense and confusing API. This library is designed for libraries using a 3rd party hosted Evergreen instance to built tools to interact with Evergreen from the client side, such as:

  • scripting things
  • building simple web views
  • building simple CLI applications

NodeJS OpenSRF Library

This library is designed for client NodeJS applications to talk to Evergreen servers using OpenSRF over websockets.

It is based heavily on the OpenSRF Javascript libraries by Bill Erickson, found in the OpenSRF Git Repo. The IDL component has been derived from bits of the Angular IDL service.

This client only works with websockets. I have removed the code for other transports to simplify things.

This runs only over websockets, I have removed the code for HTTP to simplify things.

This doesn't work as as a server-side OpenSRF framework, although could be adapated to such.

Installation

npm install opensrf

Usage Examples

Basic API call

The request method returns an EventEmitter which could fire the following events:

  • response
  • complete
  • error
  • methoderror
  • transporterror
var OpenSRF = require('opensrf');

var opts = { host: "demo.evergreencatalog.com", port:"7682"};

var conn = new OpenSRF.Connection(opts);
var ses = conn.createSession("open-ils.actor");

// parses the org tree and prints the shortname of each org unit
let parseTree = function(ou) {
    ou.children().forEach( function(child) {
      console.log(child.shortname());
      parseTree(child);
    });
};
// to call more complex methods use an argument object like:
// {"method":"open-ils.something", "params":[authtoken, 123, etc]}
var req = ses.request('open-ils.actor.org_tree.retrieve');

req.on("response", function(tree) {
    parseTree(t);
    conn.close(); // close the connection when you're done
});

Promises Example

The requestPromise method returns a promise instead of an EventEmitter.

//... create connection and session first, then:
var req = ses.requestPromise('open-ils.actor.org_tree.retrieve');

req.then( function(t) => {
    parseTree(t);
    conn.close();
}).catch( function(e){
  console.error(e);
});

Login Example

The connection object has a convenience login method which returns a promise.

conn.login("username","password")
  .then( function(authtoken){
     // do a request using authtoken here
     // if you only need one auth session, you can put it in conn.authtoken for conveience
  })
 .catch( (e) => {
   // handle errors
 })

IDL Example

To create IDL objects, access the IDL via the OpenSRF Connection. It will pull down and generate The IDL from /IDL2js based on your connection hostname.

var myAou = conn.IDL.create("aou");
myAou.shortname("FOOBAR");
myAou.name("Foobar Library");

Pcrud Search Example

The connection object also can create a handy pcrud session

conn.login("username","password")
  .then( function(authtoken) {

    var pcrud = conn.createPcrud(authToken);
    var query = {"id":1}

    pcrud.search("aou",query)
      .then(function(result){
        // do something with the results
      }
      .catch(function(err){
        // handle errors from the pcrud method
      })
    )
 })
 .catch( (e) => {
   // handle errors from the login method
 })

Pcrud Write Example

You can also use pcrud to update records

conn.login("username","password")
  .then( function(authtoken) {

    var pcrud = conn.createPcrud(authToken);
    var query = {"id":1}

    var commit = function(){ pcrud.commit(); conn.close(); }
    var rollback = function(){ pcrud.rollback(); conn.close(); }

    var createAou = function(){
      pcrud.create(myAou)
        .then(commit)
        .catch(rollback);
    }

    pcrud.begin()
      .then( createAou )
      .catch( rollback );
 })
 .catch( (e) => {
   // handle errors from the login method
 })