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

nerm

v1.5.3

Published

A route generator to match your models, yeah!

Downloads

6

Readme

nerm

NERM!!!

RESTful API generator for Express and Mongoose. Nerm maps routes directly to your mongoose models.

Nerm came about because we needed a light weight API generator. Nerm's feature set is small but useful. If you need a more full featured generator, check out Express Restify Mongoose.

Installation

npm install nerm

Basic Usage

var Nerm = require('nerm')
var mongoose = require('mongoose')

mongoose.connect('mongodb://localhost')

var Schema = new mongoose.Schema({
  name: String,
  location: String
})

var User = mongoose.model('User', Schema)

Nerm.route(app, User)
GET    /api/v0/users
POST   /api/v0/users
GET    /api/v0/users/ffffffffffffb00000000001
PUT    /api/v0/users/ffffffffffffb00000000001
DELETE /api/v0/users/ffffffffffffb00000000001

Queries

Queries in GET requests are made by passing a mongo query as a JSON string. To make a Regexp query, use the $like operator.

var q = JSON.stringify({location: 'New York', $like: {name: 'john'}})
request.get('/api/v0/users?q=' + q)
// Translates to {location: 'New York', name: /john/i}

Sort Select and Populate

GET requests can also be given sort, select, and populate options.

request.get('/api/v0/users?select=name&sort=-name')
// Will return objects without location info and sorted by name in descending order

Middleware

Middleware can be provided in order to restrict access to routes

  //This will restrict access to a individual user unless that user makes the request
  Nerm.app.route(app, User, {
    middleware: function(req, res, next) {
      if (req.params.id && req.params.id !== req.user._id)
        res.status(401).send("Unauthorized")
      else
        next()
    }
  })

Private Fields

Schemas can be decorated with a private option.

var Schema = new mongoose.Schema({
  name: String,
  location: {type: String, nerm: {private: true}}
})

var User = mongoose.model('User', Schema)

Nerm.route(app, User, {
  privateAccess: function(req) { return req.user.admin }
})
// This will not allow nonadmins to filter or modify location,
// and will not return location fields in the responses.

Readonly Fields

Schemas can be decorated with a readOnly option.

var Schema = new mongoose.Schema({
  name: String,
  location: {type: String, nerm: {readOnly: true}}
})

var User = mongoose.model('User', Schema)

Nerm.route(app, User, {
  writeAccess: function(req) { return req.user.admin }
})
// This will allow location to be filtered, but not modified by nonadmins

Scope

Sometimes a resource needs to be further restricted. To do that pass a scope function or literal. The function can be syncronous or asyncronous.

Nerm.route(app, User, {
  scope: {location: 'New York'}
})

Nerm.route(app, User, {
  scope: function(req) { return {location: req.user.location }}
})

Nerm.route(app, User, {
  scope: function(req, cb) { cb({location: req.user.location})}
})
// Callers will only be able to retrieve other users in their location.

Defaults

Default options can be provided by calling Nerm.defaults, these will apply to all routes not given their own options

Nerm.defaults({
  privateAccess: function() { return false; }
})

Nerm.route(app, User) //No callers will have access to private fields now