Node.js bindings for pmemkv
This is experimental pre-release software and should not be used in production systems. APIs and file formats may change at any time without preserving backwards compatibility. All known issues and limitations are logged as GitHub issues.
- Node.js 6.10 or higher
- PMDK - native persistent memory libraries
- pmemkv - native key/value library
- node-addon-api, node-bindings, node-gyp - for native library integration
- Used only for testing:
- chai - test assertion library
- chai-string - string assertion library
- mocha - test framework
Start by installing pmemkv on your system.
Add npm module to your project:
npm install pmem/pmemkv-nodejs --save
This library includes a set of automated tests that exercise all functionality.
npm test
We are using /dev/shm
to
emulate persistent memory
in this simple example.
const pmemkv = require('pmemkv');
function assert(condition) {
if (!condition) throw new Error('Assert failed');
}
console.log('Starting engine');
const kv = new KVEngine('vsmap', '{"path":"/dev/shm/"}');
console.log('Putting new key');
kv.put('key1', 'value1');
assert(kv.count === 1);
console.log('Reading key back');
assert(kv.get('key1') === 'value1');
console.log('Iterating existing keys');
kv.put('key2', 'value2');
kv.put('key3', 'value3');
kv.all((k) => console.log(` visited: ${k}`));
console.log('Removing existing key');
kv.remove('key1');
assert(!kv.exists('key1'));
console.log('Stopping engine');
kv.stop();