Registry / database / mongoose-rest-endpoints

mongoose-rest-endpoints

JSON →
library4.0.2jsnpmunverified

Middleware for Express that automatically generates RESTful endpoints from Mongoose schemas. Provides CRUD operations (create, read, update, delete) with customizable routes, search, and pagination. Version 4.0.2 supports Express 4.x and Mongoose 4.x/5.x. Released monthly, it differentiates by offering a declarative approach to building REST APIs with minimal boilerplate, including built-in validation and error handling.

npm install mongoose-rest-endpoints
INSTALL
IMPORT
SIG · MONGOOSE-REST-ENDP
M
mongoose-rest-endpoints
databasejavascriptv4.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import mongooseRestEndpoints from 'mongoose-rest-endpoints'
const endpoints = require('mongoose-rest-endpoints')
ESM import is the standard; CommonJS require may work if package supports it (check exports)
endpoints
const endpoints = require('mongoose-rest-endpoints')
const { endpoints } = require('mongoose-rest-endpoints')
Default export is a function, not a named export
Type definitions
import type { EndpointsOptions } from 'mongoose-rest-endpoints'
TypeScript users can import types for options if bundled with package

Creates a REST API endpoint for User model with automatic CRUD routes under /api/users.

import express from 'express'; import mongoose from 'mongoose'; import endpoints from 'mongoose-rest-endpoints'; const app = express(); app.use(express.json()); await mongoose.connect('mongodb://localhost/test'); const UserSchema = new mongoose.Schema({ name: String, email: String }); app.use('/api/users', endpoints(UserSchema)); app.listen(3000);
Debug
Known issues
gotchaMiddleware must be placed after express.json() to parse request bodies
fix
Ensure app.use(express.json()) precedes endpoint middleware.
affects: >=1.0
deprecatedOptions like 'limit' have been replaced with 'paginate' in v4
fix
Use { paginate: { default: 20 } } instead of { limit: 20 }.
affects: >=4.0.0
breakingDefault export is now ESM-only as of v4; require() fails in CommonJS
fix
Use dynamic import or set type: module in package.json.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: endpoints is not a function
Using require() on an ESM-only export in CommonJS
fix
Use import or dynamic import: const endpoints = (await import('mongoose-rest-endpoints')).default
MissingSchemaError: Schema hasn't been registered for model
Model not compiled before passing to endpoints()
fix
Create a Mongoose model from the schema before passing to endpoints: const User = mongoose.model('User', schema)
Cannot read properties of null (reading 'name')
Route parameter missing in request URL
fix
Ensure your request includes an ID parameter (e.g., /api/users/123)
Upgrade
Version history
4.0.2latest on npm
Audit
Dependencies
mongooserequiredModels and schemas are used to define endpoints
expressrequiredMiddleware is designed for Express applications
Agent activity
9 hits · last 30 days
node
8
Resources
mongoose-rest-endpoints — npm install mongoose-rest-endpoints · libregistry