Reputation: 1820
I have a need to store some meta-data in a node.js application I am writing. Rather than come up with my own file format and managing that file, I would like to use an in-process persistant key-value store.
I was looking at mongodb but it seems that mongodb must always be run out-of-process (that is, you need to start a mongo server first, then connect to it in node.js.) I require that whatever store this is, that it exist entirely within the node.js process - or at least that any external processes are entirely managed transparently by the library, and kills them when the application closes the connection.
I don't care much about performance, but it would be nice to support asynchronous IO to the store to keep up with Node's whole async thing.
It would also be nice if the store supported indexes, as I will definitely be querying the data in a way where indexes would be helpful.
I'm pretty sure that 'sqlite' would work for me, except that I don't really see it as being nearly as convenient as a key-value store. Ideally I should be able to speak in JSON, not SQL. But sqlite will work if nothing better exists.
Thanks!
Upvotes: 6
Views: 8394
Reputation: 34313
Take a look at levelup. This a wrapper around leveldb. The levelup wrapper installs leveldb via npm and runs entirely within your node process.
There are many databases built on top of leveldb. Take a look at https://github.com/rvagg/node-levelup/wiki/Modules for a list.
For convenience you can use the level package which bundles both levelup and leveldown together
Upvotes: 1
Reputation: 11064
I think you might be interested in final-db.
FinalDB uses file system to store it's data. It's not key-value store but document-based nosql solution. It supports indexes (maps) - you can specify map functions on each collection and of course it's an in process solution.
Upvotes: 1
Reputation: 311
Take a look to https://github.com/sergeyksv/tingodb. It is closely compatible to MongoDB API so you can upgrade to MongoDB when you'll need it.
Upvotes: 3
Reputation: 4125
Try nStore.
https://github.com/creationix/nstore
It's in process key-value store. Simple to use as well.
Upvotes: 3
Reputation: 37151
You might be interested in using redis http://redis.io/
There is a popular helper library for node https://github.com/mranney/node_redis
Then you can do this:
var redis = require("redis");
var client = redis.createClient();
client.set("foo_rand000000000000", "OK");
Upvotes: 3
Reputation: 43243
How about...
var store = { };
//store 'myKey'
store.myKey = { foo: 'bar' };
//fetch 'myKey'
var x = store.myKey;
Also, Googling with almost exactly your question title, you would have found http://pgte.github.com/alfred/
I don't really think there are very many particularily stable ones available yet. The external offerings are quite good though (eg. Redis)
Upvotes: -1