Node KV Storage
Wrapper around node-persist
that implements the std:kv-storage
interface.
Why
- Standardized API
- Easier code sharing with frontend
- No
await init()
How
const { default: storage, NodeStorageArea } = require('node-kv-storage')
;(async () => {
await storage.set('test', { a: 3 })
assert.deepStrictEqual(await storage.get('test'), { a: 3})
await nodePersist.init()
await nodePersist.setItem('foo', { b: 4 })
assert.deepStrictEqual(await storage.get('foo'), { b: 4})
await storage.set(3, { f: 8 })
assert.deepStrictEqual(await storage.get(3), { f: 8 })
const d = new Date(0)
await storage.set(d, { c: 5 })
assert.deepStrictEqual(await storage.get(d), { c: 5 })
await storage.set(['foo', 3, d], { c: 6 })
assert.deepStrictEqual(await storage.get(['foo', 3, d]), { c: 6 })
const other = new NodeStorageArea('other_area')
await other.set('test', { i: 11 })
assert.deepStrictEqual(await other.get('test'), { i: 11 })
})()
API