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.
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.
Package exposes a default export (ESM). CJS require works but may not infer TypeScript types.
import crud from 'express-crud-router'
Type-only import for TypeScript users; CrudOptions defines the actions object shape.
import type { CrudOptions } from 'express-crud-router'
Type for the request object passed to action handlers, contains filter, limit, offset, order.
import type { CrudRequest } from 'express-crud-router'
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}`));
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.