5

I need to implement a simple key-value storage for a nodejs application, for some environmental restrictions I can only use an embedded storage solution, meaning I can't use engines that work as a separate server/process (E.g. Mongodb, mysql, etc).

For some corporate restrictions I can't use sqlite, which was the first option that came to mind.

I investigated the following alternatives to sqlite:

I don't have any experience working with these engines, can somebody provide notes or suggentions on these? And of course any other alternative for me to check out is greatly welcomed.

Edit:

With further investigation I found

Which seem more suitable for Nodejs.

matix
  • 79
  • 1
  • 5
  • 1
    **Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic** for Stack Overflow as they tend to attract opinionated answers and spam. Thus I flagged this question accordingly. – Filnor Aug 17 '18 at 07:58

3 Answers3

4

Of the noted databases, the most well supported by Node.js is leveldb, via the level module. Just

npm install level

for everything you need to get started. level is a metapackage that bundles levelUP (exposes the leveldb methods) and levelDOWN (compiles and provides an interface to leveldb). See the levelUP documentation for the exports provided by level.

It's worth noting that this is a suitable solution only if your application will be running on a single machine, since the database is saved to the filesystem. If you scale to multiple servers you'll need to move away from an embedded datastore.

qubyte
  • 17,558
  • 3
  • 30
  • 32
  • 1
    I like your answer, and leveldb looks awesome, but I think i'm going to go with NEDB, precisely for the scalability factor. NEDB uses a subset of mongodb's query syntax, so if at any point I need to distribute the app on multiple server, I can easily switch to mongo. Thanks for your response. – matix Feb 05 '14 at 14:36
2

I was asking my self the same question 1 year ago, and I went with EJDB.

I needed a portable local storage for a "local" backend.

I've tried it so far with the following configurations:

  • MacOSX + node.js + EJDB

  • Windows 7 + node.js + EJDB

  • Debian + node.js + EJDB

It worked fine for 10 users. I guess you could have more: i'm just guessing.

0

json-lines format - it's json, separated by newlines

https://github.com/AlCalzone/jsonl-db - creates a file where each line is in {"k": "mykey", "v": anything }

const { JsonlDB } = require('@alcalzone/jsonl-db')

db = new JsonlDB(mydbpath)
await db.open()
db.set(key, value)
await db.close()
srghma
  • 4,770
  • 2
  • 38
  • 54