Registry / devops / express-crud-router

express-crud-router

JSON →
library8.1.0jsnpmunverified

A minimal Express.js middleware that automatically exposes CRUD (Create, Read, Update, Delete) routes compatible with React Admin's Simple Rest Data Provider. Version 8.1.0 is current, with a stable release cadence (major updates every few months). ORM-agnostic: works with any data source via connectors (e.g., Sequelize, Mongoose, Knex). Key differentiators: one line per resource, automatic route generation, built-in pagination with X-Total-Count header, and custom filter support. Ships TypeScript types. Peer dependency on Express ^4.0.0.

npm install express-crud-router
INSTALL
IMPORT
SIG · EXPRESS-CRUD-ROUTE
E
express-crud-router
devopsjavascriptv8.1.0
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 crud from 'express-crud-router'
✗ const crud = require('express-crud-router')
Package exposes a default export (ESM). CJS require works but may not infer TypeScript types.
crud (type)
✓ import type { CrudOptions } from 'express-crud-router'
Type-only import for TypeScript users; CrudOptions defines the actions object shape.
CrudRequest
✓ import type { CrudRequest } from 'express-crud-router'
Type for the request object passed to action handlers, contains filter, limit, offset, order.

Demonstrates basic CRUD route setup with in-memory data store, including get, create, update, and destroy handlers.

import express from 'express'; import crud from 'express-crud-router'; const app = express(); app.use(express.json()); // In-memory data store for demonstration const users = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, ]; app.use( crud('/admin/users', { get: ({ filter, limit, offset, order }) => { const filtered = users.filter(u => filter ? u.name.includes(filter.name) : true ); const total = filtered.length; const rows = filtered.slice(offset, offset + limit); return { rows, total }; }, create: (body) => { const id = users.length + 1; users.push({ id, ...body }); return { id }; }, update: (id, body) => { const index = users.findIndex(u => u.id === Number(id)); if (index === -1) throw new Error('Not found'); users[index] = { ...users[index], ...body }; return users[index]; }, destroy: (id) => { const index = users.findIndex(u => u.id === Number(id)); if (index === -1) throw new Error('Not found'); users.splice(index, 1); return { id }; }, }) ); const PORT = process.env.PORT ?? 3000; app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
Debug
Known issues
gotchaUsing Content-Range header instead of X-Total-Count may cause issues in Chrome/Safari. Always use X-Total-Count for pagination with React Admin.
fix
Upgrade to >=8.0.0 or ensure your connector returns total in X-Total-Count header.
affects: <8.0.0
deprecatedThe older Content-Range header behavior is deprecated in favor of X-Total-Count.
fix
Use X-Total-Count header; content-range is ignored unless Range request header is present.
affects: >=8.0.0
gotchaDestroy action returning null disables the route; can cause confusion if you expect the route to exist but return 404.
fix
Set destroy handler to null explicitly to disable; ensure other actions are not null inadvertently.
affects: >=1.0.0
gotchaCustom filters with conflicting keys will override each other; order is not guaranteed.
fix
Avoid returning same key from multiple filter handlers; merge manually if needed.
affects: >=1.0.0
gotchaPackage is ESM-only since v8; require() will fail if using older Node or CJS projects.
fix
Use import syntax or enable ESM in your project (type: module in package.json).
affects: >=8.0.0
Errors
Common errors & fixes
Cannot find module 'express-crud-router'
Package not installed or not in node_modules.
fix
Run 'npm install express-crud-router' and ensure it's in dependencies.
TypeError: crud is not a function
Using default import incorrectly or package is CJS parsed as ESM.
fix
Use 'import crud from "express-crud-router"' (default import) or 'const crud = require("express-crud-router").default' if in CJS environment.
Property 'rows' is missing in type 'Promise<{ total: number; rows: any[] }>'
Action handler for 'get' returns incorrect shape.
fix
Ensure get handler returns an object with 'rows' (array) and 'total' (number).
Route not found for method POST /admin/users
Destroy handler set to null preventing creation? Actually, create and destroy are separate; likely route not mounted correctly.
fix
Check that app.use(crud(...)) is called with correct path and that actions object includes 'create' handler.
Upgrade
Version history
8.1.0latest on npm
Audit
Dependencies
expressrequiredPeer dependency; required to mount CRUD routes.
Agent activity
8 hits · last 30 days
node
8
Resources
express-crud-router — npm install express-crud-router · libregistry