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

mavericks

v1.0.1

Published

A simple RESTful API to your (Mon)Goose.

Downloads

27

Readme

Mavericks

npm shield npm shield Build Status

Mavericks is a simple RESTful API wrapper around the ExpressJS framework utilizing mongoose as the schema generator, and connection to your MongoDB instance

Getting Started

Run npm install --save mavericks to add mavericks to your project.

Basic Usage

Once installed, you can initialize an ExpressJS app with the Mavericks default settings in your app.js/server.js by:

var Mavericks = require("mavericks");
var app = new Mavericks();

// Do some stuff to your express server
// ...

// Start our server
app.listen(3000, function(){
  console.log("Express server listening on port 3000")
})

Options

options.src

  • type: string
  • default: path.resolve(__dirname, 'models')

This is the path to your Mongoose Schema Files

options.db

  • type: string
  • default: 'mongodb://@localhost:27017/data'

This is the path to your MongoDB

options.logger

  • type: string
  • default: 'dev'

Basic Mongoose Schema

module.exports = {
  name: String,
  email: String
};

This basic example simply exposes a new object to be required and ran through mongoose.Schema

Modifying default routes

In order to modify the base routes used by Mavericks, simply expose your model schema as a function, and Mavericks will pass in our express instance so route overrides/addition can be made

Note: This requires mongoose to be installed as a dependency if you would like to access your model

var mongoose = require("mongoose");
var Schema = mongoose.Schema;

module.exports = function(app){
  var schema = {
    name: String,
    email: String
  }
  var model = new Schema(schema);

  app.get("my_model/", function(req, res, next){
    // some arbitrary get method used in place
    // of a default get route  

    mongoose.model('Model', model).find({}, function(e, results){
      // ...
    })
  });

  return schema;
}

Default routes

By default Mavericks creates all the RESTful routes required by an API

get

  • type: Array
  • return: objects of the collection

get :collection/:id

  • id: id of the object
  • return_type: Object
  • return: object from the collection. Empty object if nothing

get :collection/:id*

  • id*: comma separated list of ids
  • return_type: Array
  • return: objects form the requested _ids

post :collection/

  • return_type: Object
  • return: The saved model with _id

put :colleciton/:id

  • id: id of the object to update
  • return_type: String
  • return: success/error

delete :collection/:id

  • id: id of the object to delete
  • return_type: String
  • return: success/error

delete :collection/:id*

  • id*: comma separated list of ids to delete
  • return_type: String
  • return: success/error

Tests

Mavericks' test suite utilizes gulp to start a mongod instance, and expressjs server instance importing test schemas into Mavericks, and the runs a series of mocha tests. The src can be found at test/.

To run the tests

git clone [email protected]:morriswchris/mavericks
npm install
npm test

If you would just like to test locally, you can also start the test server by running npm start and the express server will start up at 0.0.0.0:3000 (Note: this will require a running mongodb service on the default port)

Contributions

All contributions welcome. Please fork and submit a pull request ... suggestions are also welcome!