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

cramit

v0.0.3

Published

<a href="https://nodei.co/npm/cramit/" target="_blank"><img src="https://nodei.co/npm/cramit.png?downloads=true&downloadRank=true"></a>

Readme

Cramit

Cram data into your database easily for testing, demos, or whatever.

Getting Started

Install Cramit using npm and save it as a dependency in your package.json.

npm install cramit --save

You can require Cramit just like every other node.js module.

var cramit = require('cramit');

In order to define the data that will be added or removed from the database one or more fixtures must be created.

Note: The fixture file names must follow the configuration you set for Crave in Cramit's configuration object. By default, Crave looks for and requires any file that contains "_fixture" in the name.

// Filename: user_fixture.js

module.exports = function(cramit, options) {

  function UserFixture() {
    cramit.fixtureSuper(this, 'User');
  }

  UserFixture.prototype = cramit.fixturePrototype();

  // Returns a new user not already in the database.
  UserFixture.prototype.getNew = function() {
    return {
      "_id": "999999999999999999999999",
      "activated": true,
      "email": "[email protected]",
      "name": "Kevin Mitnick"
    };
  };

  // Returns a list of users to be added/removed from the database.
  UserFixture.prototype.getAll = function() {
    return [
      {
        "_id": "000000000000000000000000",
        "activated": true,
        "email": "[email protected]",
        "name": "Charlie Kelly"
      },
      {
        "_id": "000000000000000000000001",
        "activated": false,
        "email": "[email protected]",
        "name": "Mac's Mom"
      }
    ];
  };

  return new UserFixture();
};

After the fixtures have been created you can call findAllFixturesAndUpsertData(). This will search for all fixture files and upsert the data returned from each fixture's getAll() method.

cramit.findAllFixturesAndUpsertData(applicationPath, {}, function(err, results) {
  if(err) {
    console.log(err);
  } else {
    console.log(results);
  }
});

API

The Cramit API consists of the following methods.

  • Find All Fixtures
  • Find All Fixtures and Insert Data
  • Find All Fixtures and Remove Data
  • Find All Fixtures and Upsert Data
  • Fixture Super
  • Fixture Prototype
  • Get All Fixture Data Object
  • Insert Fixture Data
  • Format Fixtures
  • Remove Fixture Data
  • Set Config
  • Upsert Fixture Data

Fixture

Data you want to load into a database is defined in a fixture. A fixture is a pseudo "child class" that overrides a few methods called by the Cramit library. The data methods overridden in a fixture, such as getNew() and getAll(), return data objects to be loaded into the database. Let's look at an example of a user model and fixture.

// Filename:  user_model.js
// Description:  The user model defines the how the data is stored in the database.

module.exports = function() {
  var db = require('mongoose');
  var ObjectId = db.Schema.ObjectId;

  var User = new db.Schema({
    activated:   { type: Boolean, default: true },
    email:       { type: String                 },
    name:        { type: String                 }
  });

  var UserSchema = db.model('User', User);
};
// Filename:  user_fixture.js
// Description:  Defines data and methods for adding or removing data to/from the database.

module.exports = function(cramit, options) {

  function UserFixture() {
    cramit.fixtureSuper(this, 'User');
  }

  UserFixture.prototype = cramit.fixturePrototype();

  // Returns a new user not already in the database.
  UserFixture.prototype.getNew = function() {
    return {
      "_id": "999999999999999999999999",
      "activated": true,
      "email": "[email protected]",
      "name": "Kevin Mitnick"
    };
  };

  // Returns a list of users to be added/removed from the database.
  UserFixture.prototype.getAll = function() {
    return [
      {
        "_id": "000000000000000000000000",
        "activated": true,
        "email": "[email protected]",
        "name": "Charlie Kelly"
      },
      {
        "_id": "000000000000000000000001",
        "activated": false,
        "email": "[email protected]",
        "name": "Mac's Mom"
      }
    ];
  };

  return new UserFixture();
};

Fixture Methods

When implementing a fixture you may want to override one or more methods. The following is a list of possible methods.

  • Compare
  • Delete All
  • Find By ID
  • Find In Dataset By ID
  • Get All
  • Get All and New
  • Get New
  • Insert All
  • Populate ID
  • Populate IDs
  • Populate ID from Dataset
  • Populate IDs from Dataset
  • Upsert All

The current implementation of these methods can be found here.

Config

You can configure Cramit using the setConfig(myConfigObject) method. Pass along an object with any of the properties you wish to override. For example:

var cramit = require('cramit');
var mongoose = require(mongoose);

cramit.setConfig({
  database: {
    type: 'mongoose',         // Set the type of database and connection.
    instance: mongoose        // Pass along the database connection object.
  }
});

The available properties are:

| Property | Type | Default | Description | |----------|------|---------|-------------| | crave | Object | | Accepts a Crave configuration object to define how models and fixtures are required. | | database | Object | | An object containing configuration properties related to the database. | | database.connectionUri | String | undefined | The URI used to connect to a database. You may alternately choose to specify the database instance. | | database.idAttributeName | String | undefined | The key used by all records as the unique identifier. For example mongoose uses _id. | | database.instance | String | undefined | The database connection object. You may alternately choose to specify a connection URI instead. | | database.type | String | undefined | Defines which database adapter to use. Available options are: mongoose.| | debug | Boolean | false | When true, Cramit will display log messages. | | error | Boolean | true | When true, Cramit will display error log messages. | | trace | Boolean | false | When true, Cramit will display trace log messages. |

Debug

Debugging Cramit can be done using the debug, trace, and error flags that can be toggled on/off using the config. When enabling these flags additional logging will be enabled allowing you to find issues within Cramit easier.

Documentation

Further documentation can be found in the wiki.

MIT License