{"id":14957586,"url":"https://github.com/nicgirault/express-crud-router","last_synced_at":"2026-04-17T06:01:40.817Z","repository":{"id":37672889,"uuid":"217473636","full_name":"nicgirault/express-crud-router","owner":"nicgirault","description":"Simply expose resource CRUD (Create Read Update Delete) routes for Express \u0026 Sequelize. Compatible with React Admin Simple Rest Data Provider","archived":false,"fork":false,"pushed_at":"2024-06-19T19:45:59.000Z","size":793,"stargazers_count":135,"open_issues_count":6,"forks_count":31,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-02T04:41:29.356Z","etag":null,"topics":["crud","crud-generator","express","express-js","expressjs","react-admin","sequelize"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicgirault.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-25T07:12:44.000Z","updated_at":"2025-12-19T09:52:12.000Z","dependencies_parsed_at":"2024-06-19T06:14:46.808Z","dependency_job_id":"9bd34985-4dcd-45b6-9b03-b6ecc0d9c706","html_url":"https://github.com/nicgirault/express-crud-router","commit_stats":{"total_commits":154,"total_committers":11,"mean_commits":14.0,"dds":"0.36363636363636365","last_synced_commit":"330dafe844606a9fdbfce63904eddad16f7614b7"},"previous_names":["lalalilo/express-sequelize-crud","lalalilo/ra-express-sequelize-backend","lalalilo/express-crud-router"],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/nicgirault/express-crud-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicgirault%2Fexpress-crud-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicgirault%2Fexpress-crud-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicgirault%2Fexpress-crud-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicgirault%2Fexpress-crud-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicgirault","download_url":"https://codeload.github.com/nicgirault/express-crud-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicgirault%2Fexpress-crud-router/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31917372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crud","crud-generator","express","express-js","expressjs","react-admin","sequelize"],"created_at":"2024-09-24T13:15:11.911Z","updated_at":"2026-04-17T06:01:40.724Z","avatar_url":"https://github.com/nicgirault.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-crud-router\n\n[![codecov](https://codecov.io/gh/nicgirault/express-crud-router/branch/master/graph/badge.svg)](https://codecov.io/gh/nicgirault/express-crud-router) [![CircleCI](https://circleci.com/gh/nicgirault/express-crud-router.svg?style=svg)](https://circleci.com/gh/nicgirault/express-crud-router)\n\nExpose resource CRUD (Create Read Update Delete) routes in your Express app. Compatible with [React Admin Simple Rest Data Provider](https://github.com/marmelab/react-admin/tree/master/packages/ra-data-simple-rest). The lib is ORM agnostic. [List of existing ORM connectors](https://www.npmjs.com/search?q=keywords:express-crud-router-connector).\n\n```ts\nimport crud from 'express-crud-router'\n\napp.use(\n  crud('/admin/users', {\n    get: ({ filter, limit, offset, order }) =\u003e\n      User.findAndCountAll({ limit, offset, order, where: filter }),\n    create: body =\u003e User.create(body),\n    update: (id, body) =\u003e User.update(body, { where: { id } }),\n    destroy: id =\u003e User.destroy({ where: { id } }),\n  })\n)\n```\n\n### Note: `Content-Range` header\n\nFor `getList` methods, the response includes the total number of items in the collection in `X-Total-Count` header. You should use this response header for pagination and avoid using `Content-Range` header if your request does not include a `Range` header. Checkout [this](https://stackoverflow.com/questions/53259737/content-range-working-in-safari-but-not-in-chrome) stackoverflow thread for more info.\n\nIf you are using `ra-data-simple-rest`, please refer to the [documentation](https://github.com/Serind/ra-data-simple-rest#note-about-content-range) to use `X-Total-Count` for pagination.\n\n## Install\n\n```\nnpm install express-crud-router\n```\n\n## Usage\n\n### Simple use case\n\n```ts\nimport express from 'express'\nimport crud from 'express-crud-router'\nimport sequelizeCrud from 'express-crud-router-sequelize-v6-connector'\nimport { User } from './models'\n\nconst app = new express()\napp.use(crud('/admin/users', sequelizeCrud(User)))\n```\n\n### Limit actions\n\n```ts\nimport express from 'express'\nimport crud from 'express-crud-router'\nimport sequelizeCrud from 'express-crud-router-sequelize-v6-connector'\nimport { User } from './models'\n\nconst app = new express()\napp.use(\n  crud('/admin/users', {\n    ...sequelizeCrud(User),\n    destroy: null,\n  })\n)\n```\n\n### Custom filters\n\nCustom filters such as case insensitive filter can be perform like this:\n\n```ts\nimport express from 'express'\nimport { Op } from 'sequelize'\nimport crud from 'express-crud-router'\nimport sequelizeCrud from 'express-crud-router-sequelize-v6-connector'\nimport { User } from './models'\n\nconst app = new express()\napp.use(\n  crud('/admin/users', sequelizeCrud(User), {\n    filters: {\n      email: value =\u003e ({\n        email: {\n          [Op.iLike]: value,\n        },\n      }),\n    },\n  })\n)\n```\n\nCustom filter handlers can be asynchronous. It makes it possible to filter based on properties of a related record. For example if we consider a blog database schema where posts are related to categories, one can filter posts by category name thanks to the following filter:\n\n```ts\ncrud('/admin/posts', actions, {\n  filters: {\n    categoryName: async value =\u003e {\n      const category = await Category.findOne({ name: value }).orFail()\n\n      return {\n        categoryId: category.id,\n      }\n    },\n  },\n})\n```\n\nNotes:\n\n- the filter key (here categoryName) won't be passed to the underlying action handler.\n- there is no support of conflicting attributes. In the following code, one filter will override the effect of the other filter. There is no garantee on which filter will be prefered.\n\n```ts\ncrud('/admin/posts', actions, {\n  filters: {\n    key1: async value =\u003e ({\n      conflictingKey: 'hello',\n    }),\n    key2: async value =\u003e ({\n      conflictingKey: 'world',\n    }),\n  },\n})\n```\n\n### Additional attributes\n\nAdditional attributes can be populated in the read views. For example one can add a count of related records like this:\n\n```ts\ncrud('/admin/categories', actions, {\n  additionalAttributes: {\n    postsCount: category =\u003e Post.count({ categoryId: category.id })\n  },\n  additionalAttributesConcurrency: 10 // 10 queries Post.count will be perform at the same time\n})\n```\n\nadditionalAttributes function parameters are:\n- the current row\n- an object: `{rows, req}` where rows are all page rows and req is the express request.\n\nSimilarly to how react-admin deals with resource references, express-crud-router provides additional field helpers:\n- `populateReference`\n- `populateReferenceMany`\n- `populateReferenceManyCount`\n- `populateReferenceOne`\n\nUsing additionalAttributes with `populateReferenceManyCount` or `populateReferenceOne` can be useful instead of using react-admin ReferenceManyCount and ReferenceOne as they are often used in list views and generate one HTTP query per row.\n\n```ts\ncrud\u003cnumber, { id: number }\u003e('/users', {\n  get: jest.fn().mockResolvedValue({\n    rows: [{ id: 1 }, { id: 2 } , { id: 3 }],\n    count: 2\n  }),\n}, {\n  additionalAttributes: {\n    posts: populateReferenceMany({\n      fetchAll: async () =\u003e [\n        {id: 10, authorId: 1},\n        {id: 11, authorId: 1},\n        {id: 12, authorId: 2},\n      ],\n      target: 'authorId'\n    })\n  }\n})\n```\n\n### Custom behavior \u0026 other ORMs\n\n```ts\nimport express from 'express'\nimport crud from 'express-crud-router'\nimport { User } from './models'\n\nconst app = new express()\napp.use(\n  crud('/admin/users', {\n    get: ({ filter, limit, offset, order }, { req, res }) =\u003e\n      User.findAndCountAll({ limit, offset, order, where: filter }),\n    create: (body, { req, res }) =\u003e User.create(body),\n    update: (id, body, { req, res }) =\u003e User.update(body, { where: { id } }),\n    destroy: (id, { req, res }) =\u003e User.destroy({ where: { id } }),\n  })\n)\n```\n\nAn ORM connector is a lib exposing an object of following shape:\n\n```typescript\ninterface Actions\u003cR\u003e {\n  get: GetList\u003cR\u003e = (conf: {\n    filter: Record\u003cstring, any\u003e\n    limit: number\n    offset: number\n    order: Array\u003c[string, string]\u003e\n  }) =\u003e Promise\u003c{ rows: R[]; count: number }\u003e\n  create: (body: R) =\u003e Promise\u003cR \u0026 { id: number | string }\u003e\n  destroy: (id: string) =\u003e Promise\u003cany\u003e\n  update: (id: string, data: R) =\u003e Promise\u003cany\u003e\n}\n```\n\n### Search\n\n#### Autocomplete\n\nWhen using react-admin autocomplete reference field, a request is done to the API with a `q` filter. Thus, when using the autocomplete field in react-admin, you must specify the behavior to search the records. This could looks like:\n\n```ts\napp.use(\n  crud('/admin/users', , sequelizeCrud(User), {\n    filters: {\n      q: q =\u003e ({\n          [Op.or]: [\n            { address: { [Op.iLike]: `${q}%` } },\n            { zipCode: { [Op.iLike]: `${q}%` } },\n            { city: { [Op.iLike]: `${q}%` } },\n          ],\n        }),\n    },\n  })\n)\n```\n\nexpress-crud-router ORM connectors might expose some search behaviors.\n\n### Recipies\n\n#### Generic filter on related record attributes\n\n```ts\ncrud('/admin/posts', actions, {\n  filters: {\n    category: async categoryFilters =\u003e {\n      const categories = await Category.find(categoryFilters)\n\n      return {\n        categoryId: categories.map(category =\u003e category.id),\n      }\n    },\n  },\n})\n```\n\nThis code allows to perform queries such as:\n\n`/admin/posts?filter={\"category\": {\"name\": \"recipies\"}}`\n\n## Contribute\n\nThis lib uses [semantic-release](https://github.com/semantic-release/semantic-release). You need to write your commits following this nomenclature:\n\n- feat: A new feature\n- fix: A bug fix\n- docs: Documentation only changes\n- style: Changes that do not affect the meaning of the code (white-space, - formatting, missing semi-colons, etc)\n- refactor: A code change that neither fixes a bug nor adds a feature\n- perf: A code change that improves performance\n- test: Adding missing or correcting existing tests\n- chore: Changes to the build process or auxiliary tools and libraries such as documentation generation\n\nTo trigger a major version release write in the core of the commit message:\n\n```\nfeat: my commit\n\nBREAKING CHANGE: detail here\n```\n\n## Thanks\n\nThank you to [Lalilo](https://www.welcometothejungle.com/fr/companies/lalilo) who made this library live.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicgirault%2Fexpress-crud-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicgirault%2Fexpress-crud-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicgirault%2Fexpress-crud-router/lists"}