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

mongoose-crud-generator

v1.2.1

Published

A package for generating Mongoose CRUD APIs.

Readme

CRUD API Generator with Role-Based Permissions

A highly customizable CRUD API generator for Mongoose models with built-in filtering, pagination, search, population and much more.

Features

  • 🚀 Auto-generate CRUD APIs for any Mongoose model.
  • 🔐 Role-based permissions with middleware support.
  • 🔎 Advanced query support (filters, search, sort, pagination, field selection, and population).
  • 🪝 Pre and post hooks for customization.
  • 📦 Fully compatible with Express.js.

Installation

Install the package using npm:

npm install mongoose-crud-generator

Or with yarn:

yarn add mongoose-crud-generator

Setup

1. Import and Use in Express

const express = require("express");
const mongoose = require("mongoose");
const { generateCrudRoutes } = require("mongoose-crud-generator");
const User = require("./models/User"); // Example Mongoose model

const app = express();
app.use(express.json());

// Define API options
const options = {
  authOptions: { authenticate: true, authMiddleware: require("./middlewares/auth") },
  preHooksOptions: { getAll: async (req, res) => console.log("Pre Hook Triggered") },
  postHooksOptions: { getAll: async (req, res, response) => response },
  middlewareOptions: { customMiddleware: require("./middlewares/customMiddleware") },
};

// Generate routes
const userRoutes = generateCrudRoutes({ model: User, modelName: "User", ...options });
app.use("/users", userRoutes);

// Start server
app.listen(3000, () => console.log("Server running on port 3000"));

API Endpoints

1. Get All Items

GET /users?page=1&limit=10&search=John&filter={"age":{"$gte":25}}

Query Parameters:

  • page: Pagination (default: 1)
  • limit: Items per page (default: 10)
  • search: Search by name or custom fields
  • searchFields: Search Fields key in collection
  • filter: JSON object for advanced filtering
  • sort: Sort the output in order (default: -updatedAt)
  • join: Populate related fields (field(field1[field2,field3]) format) // () for nested joins and [] for selecting specific fields after join
  • select: Select specific fields (field1,field2 format)
  • pipeline: Skips all other query params (excepts page and limit) and only run the aggregation pipeline to find the result

2. Get Item by ID

GET /users/:id

3. Create New Item

POST /users
Content-Type: application/json
{
  "name": "John Doe",
  "email": "[email protected]",
  "age": 30
}

4. Update Item

PUT /users/:id
Content-Type: application/json
{
  "name": "John Updated",
  "age": 31
}

5. Soft Delete Item

DELETE /users/:id

6. Hard Delete Item

DELETE /users/hard/:id

Authentication & Role-Based Access Control

You can add authentication and role-based permissions with middleware:

const options = {
  authOptions: { authenticate: true, authMiddleware: require("./middlewares/auth") }
};

Hooks for Custom Logic

Customize API logic using pre and post hooks:

const options = {
  preHooksOptions: { getAll: async (req, res) => console.log("Pre Hook") },
  postHooksOptions: { getAll: async (req, res, response) => response },
};

Versioning

Use semantic versioning:

npm version patch # Bug fixes
npm version minor # New features
npm version major # Breaking changes

Contributing

Pull requests are welcome! Open an issue for discussions.

License

MIT