{"id":13780186,"url":"https://github.com/feathersjs-ecosystem/feathers-nedb","last_synced_at":"2025-05-11T13:31:34.643Z","repository":{"id":33515617,"uuid":"37161610","full_name":"feathersjs-ecosystem/feathers-nedb","owner":"feathersjs-ecosystem","description":"A service using NeDB, an embedded datastore for Node.js","archived":false,"fork":false,"pushed_at":"2024-10-01T01:11:46.000Z","size":1440,"stargazers_count":83,"open_issues_count":13,"forks_count":19,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-03T19:35:25.092Z","etag":null,"topics":["feathers-service-adapter","feathersjs","nedb"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feathersjs-ecosystem.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/contributing.md","funding":null,"license":"LICENSE","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":"2015-06-09T22:15:19.000Z","updated_at":"2023-11-27T19:02:21.000Z","dependencies_parsed_at":"2024-01-17T00:55:07.405Z","dependency_job_id":"c096833a-5dfc-4478-accc-f9affac80128","html_url":"https://github.com/feathersjs-ecosystem/feathers-nedb","commit_stats":{"total_commits":185,"total_committers":12,"mean_commits":"15.416666666666666","dds":0.5135135135135135,"last_synced_commit":"5d8f84bb723c8ead9dbb70b422ff94b90330ed1d"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feathersjs-ecosystem%2Ffeathers-nedb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feathersjs-ecosystem%2Ffeathers-nedb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feathersjs-ecosystem%2Ffeathers-nedb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feathersjs-ecosystem%2Ffeathers-nedb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feathersjs-ecosystem","download_url":"https://codeload.github.com/feathersjs-ecosystem/feathers-nedb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224151116,"owners_count":17264426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["feathers-service-adapter","feathersjs","nedb"],"created_at":"2024-08-03T18:01:13.164Z","updated_at":"2024-11-17T15:30:57.986Z","avatar_url":"https://github.com/feathersjs-ecosystem.png","language":"TypeScript","readme":"# feathers-nedb\n\n[![Download Status](https://img.shields.io/npm/dm/feathers-nedb.svg?style=flat-square)](https://www.npmjs.com/package/feathers-nedb)\n\n[feathers-nedb](https://github.com/feathersjs-ecosystem/feathers-nedb/) is a database service adapter for [NeDB](https://github.com/seald/nedb), an embedded datastore with a [MongoDB](https://www.mongodb.org/) like API. NeDB can store data in-memory or on the filesystem which makes it useful as a persistent storage without a separate database server.\n\n```bash\n$ npm install --save @seald-io/nedb feathers-nedb\n```\n\n\u003e **Important:** `feathers-nedb` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).\n\n## API\n\n### `service(options)`\n\nReturns a new service instance initialized with the given options. `Model` has to be an NeDB database instance.\n\n```js\nconst NeDB = require(\"@seald-io/nedb\");\nconst service = require(\"feathers-nedb\");\n\n// Create a NeDB instance\nconst Model = new NeDB({\n  filename: \"./data/messages.db\",\n  autoload: true,\n});\n\napp.use(\"/messages\", service({ Model }));\napp.use(\"/messages\", service({ Model, id, events, paginate }));\n```\n\n**Options:**\n\n- `Model` (**required**) - The NeDB database instance. See the [NeDB API](https://github.com/seald/nedb#documentation) for more information.\n- `id` (_optional_, default: `'_id'`) - The name of the id field property. By design, NeDB will always add an `_id` property.\n- `events` (_optional_) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service\n- `paginate` (_optional_) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size\n- `whitelist` (_optional_) - A list of additional query parameters to allow (e.g. `[ '$regex' ]`)\n- `multi` (_optional_) - Allow `create` with arrays and `update` and `remove` with `id` null to change multiple items. Can be `true` for all methods or an array of multi methods (e.g. `[ 'remove', 'create' ]`)\n\n### params.nedb\n\nWhen making a [service method](https://docs.feathersjs.com/api/services.html) call, `params` can contain an `nedb` property which allows to pass additional [NeDB options](https://github.com/seald/nedb#updating-documents), for example to allow `upsert`:\n\n```js\napp.service(\"messages\").update(\n  \"someid\",\n  {\n    text: \"This message will be either created or updated\",\n  },\n  {\n    nedb: { upsert: true },\n  }\n);\n```\n\n### use of params on client\n\nOn client you can't pass anything other than a query as the parameter. So you need to do it like this.\n\n```js\n// client side\napp.service(\"messages\").update(\n  \"someid\",\n  {\n    text: \"This message will be either created or updated\",\n  },\n  {\n    query: { nedb: { upsert: true } },\n  }\n);\n```\n\nthen add a hook to the service to move the nedb options to the params object\n\n```js\n(ctx) =\u003e {\n  const nedb = ctx.params.query.nedb;\n  if (nedb) {\n    ctx.params.nedb = nedb;\n    delete ctx.params.query.nedb;\n  }\n  return ctx;\n};\n```\n\n## Example\n\nHere is an example of a Feathers server with a `messages` NeDB service that supports pagination and persists to `db-data/messages`:\n\n```\n$ npm install @feathersjs/feathers @feathersjs/errors @feathersjs/express @feathersjs/socketio feathers-nedb nedb\n```\n\nIn `app.js`:\n\n```js\nconst feathers = require(\"@feathersjs/feathers\");\nconst express = require(\"@feathersjs/express\");\nconst socketio = require(\"@feathersjs/socketio\");\n\nconst NeDB = require(\"@seald-io/nedb\");\nconst service = require(\"feathers-nedb\");\n\nconst db = new NeDB({\n  filename: \"./db-data/messages\",\n  autoload: true,\n});\n\n// Create an Express compatible Feathers application instance.\nconst app = express(feathers());\n// Turn on JSON parser for REST services\napp.use(express.json());\n// Turn on URL-encoded parser for REST services\napp.use(express.urlencoded({ extended: true }));\n// Enable REST services\napp.configure(express.rest());\n// Enable Socket.io services\napp.configure(socketio());\n// Connect to the db, create and register a Feathers service.\napp.use(\n  \"/messages\",\n  service({\n    Model: db,\n    paginate: {\n      default: 2,\n      max: 4,\n    },\n  })\n);\n// Set up default error handler\napp.use(express.errorHandler());\n\n// Create a dummy Message\napp\n  .service(\"messages\")\n  .create({\n    text: \"Message created on server\",\n  })\n  .then((message) =\u003e console.log(\"Created message\", message));\n\n// Start the server.\nconst port = 3030;\n\napp.listen(port, () =\u003e {\n  console.log(`Feathers server listening on port ${port}`);\n});\n```\n\nRun the example with `node app` and go to [localhost:3030/messages](http://localhost:3030/messages).\n\n## License\n\nCopyright (c) 2019\n\nLicensed under the [MIT license](LICENSE).\n","funding_links":[],"categories":["Plugins"],"sub_categories":["Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeathersjs-ecosystem%2Ffeathers-nedb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeathersjs-ecosystem%2Ffeathers-nedb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeathersjs-ecosystem%2Ffeathers-nedb/lists"}