# nedb-promises

> A dead-simple promise wrapper for nedb.

Latest version **6.2.4** (published 2026-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install nedb-promises
pnpm add nedb-promises
yarn add nedb-promises
bun add nedb-promises
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 6.2.4 |
| Published | 2026-08-18 |
| First published | 2017-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 77.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 300 |
| Author | Kristóf Baján |
| Maintainers | bajankristof |
| Keywords | nedb, promises, promise |

## Links

- npm: https://www.npmjs.com/package/nedb-promises
- Repository: https://github.com/bajankristof/nedb-promises
- Homepage: https://github.com/bajankristof/nedb-promises#readme
- Issues: https://github.com/bajankristof/nedb-promises/issues
- npm.io page: https://npm.io/package/nedb-promises

## Dependencies (1)

- [@seald-io/nedb](https://npm.io/package/@seald-io/nedb.md) ^4.1.2

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 6.2.4 (latest) — 2026-08-18
- 6.2.3 — 2023-08-29
- 6.2.2 — 2023-08-29
- 6.2.1 — 2022-09-24
- 6.2.0 — 2022-09-24
- 6.1.0 — 2022-06-20
- 6.0.3 — 2022-02-24
- 6.0.2 — 2022-02-21
- 6.0.1 — 2022-02-21
- 6.0.0 — 2022-02-21
- 6.0.0-pre — 2022-02-21
- 5.0.3 — 2021-12-28
- 5.0.2 — 2021-11-13
- 5.0.1 — 2021-09-18
- 5.0.0 — 2021-06-15
- … 34 more at https://npm.io/package/nedb-promises/versions

## README

![nedb-promises](https://github.com/bajankristof/nedb-promises/blob/master/logo.svg "nedb-promises")

A dead-simple promise wrapper for [nedb](https://github.com/louischatriot/nedb#readme).

Check out the [docs](https://github.com/bajankristof/nedb-promises/blob/master/docs.md).

##### IMPORTANT
**As of `nedb-promises` `5.0.0` [nedb](https://github.com/louischatriot/nedb#readme) package has been replaced with a fork of the original package, [@seald-io/nedb](https://github.com/seald/nedb) to solve some vulnerability issues originating from `nedb`!**

```js
const Datastore = require('nedb-promises')
let datastore = Datastore.create('/path/to/db.db')

// #1
datastore.find({ field: true })
  .then(...)
  .catch(...)
  
// #2
datastore.find({ field: true })
  .exec(...)
  .then(...)
  .catch(...)

// #1 and #2 are equivalent

datastore.findOne({ field: true })
  .then(...)
  .catch(...)
  
datastore.insert({ doc: 'yourdoc' })
  .then(...)
  .catch(...)
  
// or in an async function
async function findSorted(page, perPage = 10) {
  return await datastore.find(...)
      .sort(...)
        .limit(perPage)
        .skip(page * perPage)
}
```

### Installation
```sh
npm install --save nedb-promises
```

### Usage
Everything works as the original module, with a couple of exceptions:
* There are no callbacks.
* `loadDatabase` has been renamed to [`load`](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Datastore+load).
* The cursor's `projection` method has been renamed to [`project`](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Cursor+project).
* You should call `Datastore.create(...)` instead of `new Datastore(...)`. This way you can access the original [nedb](https://github.com/louischatriot/nedb#readme) properties, such as `datastore.persistence`.
* As of v2.0.0 the module supports events 😎... Check out the [docs about events](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Datastore)!

Check out the [original docs](https://github.com/louischatriot/nedb#readme)!

#### load( )
You don't need to call this as the module will automatically detect if the datastore has been loaded or not upon calling any other method. 
```js
const Datastore = require('nedb-promises')
let datastore = Datastore.create('/path/to/db.db')
datastore.load(...)
  .then(...)
  .catch(...)
```

#### find( [query], [projection] ), findOne( [query], [projection] ), count( [query] )
These methods will return a Cursor object that works the same way it did before except when you call "exec" it takes no arguments and returns a Promise.
The cool thing about this implementation of the Cursor is that it behaves like a Promise. Meaning that you can `await` it and you can call `.then()` on it.

```js
const Datastore = require('nedb-promises')
let datastore = Datastore.create('/path/to/db.db')

//outside Promise chain
datastore.find(...)
  .then(...)
  .catch(...)
  
//insinde Promise chain
datastore.insert(...)
  .then(() => {
    return datastore.find(...)
  })
  .then(
    // use the retrieved documents
  )

;(async () => {
  await datastore.find(...).sort(...).limit()
})()
```

#### other( ... )
All the other methods will take the same arguments as they did before (except the callback) and will return a Promise.

Check out the [docs](https://github.com/bajankristof/nedb-promises/blob/master/docs.md).

---
_Source: https://npm.io/package/nedb-promises · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
