PhoneDB
PhoneDB is a database backed by Redis to store user contact lists. It allows you to easily find which of a user's contacts are also registered with your app. PhoneDB validates phone numbers before they are added.
Installation
If you are using yarn:
yarn add phonedb
or npm:
npm install phonedb --save
Run Redis server:
redis-server
Check out Redis quickstart to install.
Usage
Require PhoneDB:
const PhoneDB = require('phonedb');
Initialize PhoneDB, connecting to a local Redis server running on the default port:
const phoneDB = new PhoneDB();
Optionally pass in a Redis configuration to connect to a remote server.
const phoneDB = new PhoneDB(REDIS_CLOUD_URL);
Register a user's phone number with PhoneDB:
phoneDB.register('+14157775555');
Add a user's contacts:
const result = await phoneDB.addContacts(userId, ['+18473335555', '+12127775555']);
Get a user's contacts:
const contacts = await phoneDB.getContacts(userId);
Get a user's contacts who are also registered with PhoneDB (set registered = true
):
const registeredContacts = await phoneDB.getContacts(userId, true);
Get mutual contacts between two users:
const mutualContacts = await phoneDB.getMutualContacts(userId, otherUserId);
Get mutual contacts between two users who are registered:
const mutualRegisteredContacts = await phoneDB.getMutualContacts(userId, otherUserId, true);
Debugging
Add DEBUG=phonedb
to the node start script in package.json
to see debug output. i.e:
DEBUG=phonedb node server.js
Tests
yarn install
npm test
Author
Shane Vitarana :: http://shanev.me :: @shanev