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 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-crudify-mongoose

v5.0.1

Published

Express CRUDify Mongoose =========================

Downloads

24

Readme

Express CRUDify Mongoose

NPM version Build Status Coverage Status Dependency Status devDependency Status

Like express-restify-mongoose but with way less ambition.

Produces a simple CRUD interface.

Dependencies / tools

  • Babel
  • ..

Usage

npm install express-crudify-mongoose --save
const UserSchema = new Schema({
    name : {type: String, required: true},
    email: {type: String, required: true},
    admin: {type: Boolean, default: false, required: true},
});

const Users = db.model('user', UserSchema);
const readonly = ['admin'];

const crud = crudify({
    readonly,
    Model: Users,
});

server.use('/users', crud);

Endpoints

  • GET /users
  • POST /users
  • GET /users:_id
  • PATCH /users/:_id
  • DELETE /users/:_id

Operations

Filter

GET /users?name=Alex

Select all users with where name Alex.

The query gets forwarded straight to MongoDB, so it's possible to write queries like /posts?date[$gt]=2016-01-01T00:00:00.000Z to get all posts dated after 2016.

:warning: If you're making a public-facing API, you might want to use preBuildQuery middleware to validate the params used.

Selecting partial outputs

GET /users?$select=name,email
GET /users/:id?$select=name,email

Only output name & email.

Pagination

GET /users?$limit=10
GET /users?$limit=10&skip=10

Middlewares

Middlewares can be async by being ES7 async functions or functions returning promises.

If you pass in an array of functions, they'll be executed sequentially.

preSave

Useful for custom validation, that you'd only want to run when change is done through API request and can therefore simply not be done by Mongoose's .pre('save', fn).

const readonly = ['admin'];
const Users = db.model('user', UserSchema);

const preSave = async (user) => {
	if (user.admin) {
		let err = new Error("Can't change admin users through API");
		err.statusCode = 400;

		throw err;
	}
	let err = new Error('Validation failed');
	
	
	const newData = data;
	
	// return the newData that you want in the output
	return newData;
}

const crud = crudify({
    Model: Users,
    readonly,
    preSave, // preSave: [preSave, ..] is also supported
});

preOutput

preOutput functions will receive an object with properties data and req.

  • req is the current
  • data is the data that is currently set to be output to client.

Note that preOutput is run the same for all endpoints, so sometimes data is an array and sometimes it's a singular item.

const Users = db.model('user', UserSchema);

const preOutput = async (data) => {
	const newData = data;
	
	// return the newData that you want in the output
	return newData;
}

const crud = crudify({
    Model: Users,
    preOutput, // preOutput: [preOutput, ..] is also supported
});

Development

  1. Clone project
  • make setup
  • make run

You can run example project with make example-babel

Git Commit Messages

Based on atom & dannyfritz/commit-message-emoji.

  • Use the present tense ("Add feature" not "Added feature")

  • Use the imperative mood ("Move cursor to..." not "Moves cursor to...")

  • Limit the first line to 72 characters or less

  • Reference issues and pull requests liberally

  • Start the commit message with an applicable emoji:

    Commit Type | Emoji ---------- | ------------- Initial Commit | :tada: :tada: Version Tag | :bookmark: :bookmark: New Feature | :sparkles: :sparkles: Bugfix | :bug: :bug: Metadata | :card_index: :card_index: Documentation | :books: :books: Performance | :racehorse: :racehorse: Cosmetic/refactor | :art: :art: Lint fixes | :shirt: :shirt: Tests | :white_check_mark: :white_check_mark: Removing files | :fire: :fire: Security | :lock: :lock: Upgrade deps | :arrow_up: :arrow_up: Downgrade deps | :arrow_down: :arrow_down: General Update | :zap: :zap: Adding to debt | :mask: :mask: Other | Be creative

Code

TBC

Run project:

make run

Deploy

TBC

Documentation

Team