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

ctrllr

v0.1.11

Published

Node RESTful API testing framework.

Readme

Stories in Ready CTRLLR

API testing made easy - and it's got no vowels, so you know it's hip.

Write your tests with JSON, add custom headers, provide functions to run before and after each test, use synchronous or asynchronous calls - the sky's the limit.

Usage

test.js

var spec = require('./spec'),
    ctrllr = new require('ctrllr')({
        baseUrl: 'http://localhost:9000'
    });

ctrllr
    .add(spec)
    .start();

spec.js

module.exports = {
    description: 'Users list endpoint.',
    method: 'GET',
    url: '/api/users',
    expectStatus: 200,
    expectJSON: true,
    expectArray: true,
    expectKeys: [
        '_id',
        'username'
    ]
}

Look in the example directory for more samples. The tests are are test.js and test-2.js while the specs are in spec.js, spec-2.js, etc.

Multiple Tests

test.js

var spec1 = require('./spec'),
    spec2 = require('./spec-2'),
    spec3 = require('./spec-3'),

    ctrllr = new require('ctrllr')({
        baseUrl: 'http://localhost:9000'
    });

ctrllr
    .add(spec1)
    .add(spec2)
    .add(spec3)
    .start();

A specification can also return an array of tests:

var specs = [{
    description: 'Test one',
    url: '/api/users',
    expectStatus: 200,
    expectKeys: [
        '_id',
        'username'
    ]
}, {
    description: 'Test two',
    url: '/api/users/1',
    expectStatus: 200,
    expectKeyValue: {
        _id: 1,
        username: 'ishmaelthedestroyer'
    }
}];

ctrllr.add(specs);

Options

  • description - String basic description of specification
  • method - String request type GET || POST || PUT || DELETE || OPTIONS
  • url - String url to request
  • headers - Object || Function key / value pairs to add headers, can be function returning object
  • timeout - max time for test to run (in milliseconds), defaults to 5000
  • expectStatus - Number status to check for 200, 401, 500 etc
  • expectJSON - Boolean should check response type for JSON
  • expectArray - Boolean should check response type for Array
  • expectKeys - Array keys to check for in response
  • expectKeyValue - Object key / value pairs to check for
  • before - Function || Array function or array of functions to call before test
  • after - Function || Array function or array of functions to call after test
  • send - Object || Function object or function that returns object to send in body of request

Before & After

You can specify functions to run before and after each test.

The before function is given a helper object which can be used to set headers or add data to send in the request object.

var spec = {
    // ...
    before: function(ctrllr) {
        ctrllr.setHeader('Authorization', 'token-goes-here');
        ctrllr.send({ foo: 'bar' });
    }
};

The after function is given access to the response body and a simple assert helper. The assert helper accepts a description (string) and assertion (boolean).

var spec = {
    // ...
    after: function(response, assert) {
        assert('Response is successful', response.status === 200);
        assert('Response is an array', response.body instanceof Array);
    }
};

Both the before and after properties can either be functions or an array of functions to be called.

var spec = {
    // ...
    before: [
        function() {
            console.log('Running BEFORE function 1...');
        },
        function() {
            console.log('Running BEFORE function 2...');
        },
        function() {
            console.log('Running BEFORE function 3...');
        }
    ],
    after: [
        function() {
            console.log('Running AFTER function 1...');
        },
        function() {
            console.log('Running AFTER function 2...');
        }
    ]
};

Asychronous functions

All the options that accept functions can return deferred promises for asynchronous calls. NOTE: these functions will still be timed out if they run longer than the timeout value

var spec = {
    // ...
    before: function() {
        var deferred = require('q').defer();

        setTimeout(function() {
            deferred.resolve(true);
        }, 2000);

        return deferred.promise;
    }
};

Express server

If you're testing a Node server using Express, you pass the server to a ctrllr instance in the config block, and it will start and stop the server for the tests. In this case, you don't have to specify a baseUrl.

var spec = require('./spec'),
    app = require('./server'),
    ctrllr = new require('ctrllr')({
        server: app,
        port: 6060
    });

ctrllr
    .add(spec)
    .start();

Global configuration

If you have before functions, after functions, or headers you want applied to each test, you can specify those when creating the ctrllr instance or by calling the config function.

These functions can also be asynchronous.

var ctrllr = require('ctrllr')({
    // ...
    before: function() {
        console.log('This will run before every test.');
    },
    after: function() {
        console.log('This will run after every test.');
    },
    headers: {
        Authorization: 'token'
    }
});

Maintainers

Copyright (c) 2014 CTRL LA. This software is licensed under the MIT License.