157

Anybody know of a lightweight yet durable database, written in Javascript, that can be used with Node.js.

I don't want the 'weight' of (great) solutions like Mongo or Couch. A simple, in memory JS database with the capability to persist to disk as a file would be enough. I would only use it to store small amounts of data.

Requirements:

  • can run in process with a node.js server application
  • can save the whole database to disk and recover after a failure
  • NO need for atomic writes or transaction supports
  • fast queries and sorting would be nice
  • only needs to support small data volumes, up to 1MB in total

I've come across TAFFY db so far but it really doesn't seem optimized for use in Node.js. Anybody seen what I'm looking for out there?

Thanks

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
ConfusedNoob
  • 9,826
  • 14
  • 64
  • 85

11 Answers11

124

I had the same requirements as you but couldn't find a suitable database. nStore was promising but the API was not nearly complete enough and not very coherent.

That's why I made NeDB, which a dependency-less embedded database for Node.js projects. You can use it with a simple require(), it is persistent, and its API is the most commonly used subset of the very well-known MongoDB API.

https://github.com/louischatriot/nedb

Louis Chatriot
  • 2,031
  • 2
  • 15
  • 13
  • 12
    nedb is great, but be aware that you cannot use it across multiple processes - each one gets its own copy at startup. – Meekohi Mar 18 '14 at 20:00
  • 20
    As a heads-up it looks like NeDB might have been abandoned. – Guy Apr 08 '17 at 17:40
  • 7
    I don't understand why latest commit 1.5 years ago means the project is abandoned. It absolutely isn't, it just achieved its goal and I don't see any value in feature-creep ... – Louis Chatriot Jan 24 '18 at 12:33
  • @LouisChatriot I agree that generally I am wrong with any judgements so far. So I removed it from my initial comments. – Deilan Jan 24 '18 at 18:19
  • Thanks @Deilan and no worries of course, this is simply a question I get a lot and it always puzzles me! – Louis Chatriot Jan 25 '18 at 20:01
  • 9
    Consider having a simple script that updates the README every 3 months, replacing the last line that says "This project is still active as - NeDB (c) 2013- Louis Chatriot"; the commit message should be something like "stating that project is still active as of ", which will be the first thing people see at the top of github. – Giacomo Lacava Mar 28 '18 at 12:21
  • 11
    @LouisChatriot I have to agree. You have 107 issues, 32 PRs sitting there and last change to code was 3 years ago. Just seeing that, it's software I don't want to bring in and deal with incompatibilities (3 years in js dev is an eternity), issues that get ignored, etc. The right amount of stars but it doesn't scream fresh. – Neithan Max Dec 27 '18 at 10:35
  • 1
    @LouisChatriot, looking at the amount of stars, it's the best product mentioned here. I know you have a paypal/btc link, to refresh/bugfix the project, but would you consider promoting a gofundme (or similar) campaign where one can see a visible current/remaining goal. People (including myself), are more willing to donate to a project that has value and reputation like yours, where donation goals are clearly visible. Perception is reality, and seeing a project being outdated (whether it's feature complete or not) people are more willing to look at something else. Thank you nonetheless. – tno2007 Dec 01 '20 at 08:53
  • 3
    Officially "No longer maintained" as of July 8, 2021 – aaronP Jan 14 '22 at 21:47
31

Lokijs: A fast, in-memory document-oriented datastore for node.js, browser and cordova.

  • In-memory Javascript Datastore wih Persistence
  • In-Browser NoSQL db with syncing and persisting
  • a Redis-style store an npm install away
  • Persistable NoSQL db for Cordova
  • Embeddable NoSQL db with Persistence for node-webkit

LokiJS to be the ideal solution:

  • Mobile applications - especially HTML5 based (Cordova, Phonegap, etc.)
  • Node.js embedded datastore for small-to-medium apps
  • Embedded in desktop application with Node Webkit

https://github.com/techfort/LokiJS

Ben Davis
  • 13,112
  • 10
  • 50
  • 65
Damodaran
  • 10,882
  • 10
  • 60
  • 81
19

NeDB seems to be what you are looking for. From the blurb:

Embedded persistent database for Node.js, written in Javascript, with no dependency (except npm modules of course). You can think of it as a SQLite for Node.js projects, which can be used with a simple require statement. The API is a subset of MongoDB's. You can use it as a persistent or an in-memory only datastore.

Christof Jans
  • 1,854
  • 1
  • 17
  • 10
  • @Deilan I don't understand why latest commit 1.5 years ago means the project is abandoned. It absolutely isn't, it just achieved its goal and I don't see any value in feature-creep ... – Louis Chatriot Jan 24 '18 at 12:32
  • @LouisChatriot I agree that generally I am wrong with any judgements so far. So I removed it from my initial comments. – Deilan Jan 24 '18 at 18:20
  • Officially "No longer maintained" as of July 8, 2021 – aaronP Jan 14 '22 at 21:48
16

Take a look at http://www.tingodb.com. I believe it does what you looking for. Additionally it fully compatible with MongoDB API. This reduces implementation risks and gives you option to switch to heavy solution as your app grows.

https://github.com/sergeyksv/tingodb

Deilan
  • 4,740
  • 3
  • 39
  • 52
Sergey Korotkov
  • 311
  • 2
  • 7
  • 1
    Full compatability with MongoDB is a very nice feature - develop your app to work with small local db, then if you need to, scale up to MongoDB.... Thanks! – Brad Parks Oct 19 '16 at 00:54
  • ... but definitely don't forget to compare with [nedb](https://github.com/louischatriot/nedb), which is also MongoDB compatible, and see which works for you – Brad Parks Oct 19 '16 at 01:02
  • 1
    Latest commit on Dec 26, 2016. – Deilan Jan 24 '18 at 18:17
13

I'm only familiar with Mongo and Couch, but there's also one named Persistence.

Matt
  • 74,352
  • 26
  • 153
  • 180
Steve
  • 53,375
  • 33
  • 96
  • 141
9

Try nStore, it seems like a nice key/value lightweight dembedded db for node. See https://github.com/creationix/nstore

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
8

I had trouble with SQLite3, nStore and Alfred.

What works for me is node-dirty:

path = "#{__dirname}/data/messages.json"
messages = db path

message = 'text': 'Lorem ipsum dolor sit...'

messages.on "load", ->    
    messages.set 'my-unique-key', message, ->
        console.log messages.get('my-unique-key').text

    messages.forEach (key, value) ->
        console.log "Found key: #{key}, val: %j", value

messages.on "drain", ->
    console.log "Saved to #{path}"
Radek
  • 3,913
  • 3
  • 42
  • 37
  • Thank you for the share, I've been looking for something like this for a while. This in combination with small websites works just fine! – Dieterg Jan 18 '14 at 10:24
  • 1
    @DieterGoetelen you are welcome! I was also recently quite happy using a more powerful EJDB which has a MongoDB-like syntax and has bindings in Node.js and beyond https://github.com/Softmotions/ejdb-node – Radek Jan 18 '14 at 13:16
8

LevelUP aims to expose the features of LevelDB in a Node.js-friendly way.

https://github.com/rvagg/node-levelup

You can also look at UnQLite. with a node.js binding node-unqlite

https://github.com/symisc/unqlite

Deilan
  • 4,740
  • 3
  • 39
  • 52
user2870483
  • 81
  • 1
  • 1
7

Maybe you should try LocallyDB it's easy-to-use and lightweight in addition to the with advanced selecting system similar to javascript conditional expression...

https://github.com/btwael/locallydb

Deilan
  • 4,740
  • 3
  • 39
  • 52
Wael Boutglay
  • 1,163
  • 1
  • 15
  • 21
2

UeberDB provides abstraction for various databases

https://github.com/pita/ueberDB

https://www.npmjs.org/package/ueberDB

Deilan
  • 4,740
  • 3
  • 39
  • 52
John McLear
  • 764
  • 1
  • 10
  • 20
1

I wrote jaguarDb to handle some of the things that you are mentioning since I sometimes need a "little" database for demo or test projects too and I don't want to depend on mongoDB or another real database.

https://github.com/hectorcorrea/jaguarDb

Hector Correa
  • 26,290
  • 8
  • 57
  • 73