NodeJS express-session storage connector for IBM Cloudant. The module is build on top of the cloudant npm module with promises plugin - the official Node JS Cloudant library.
npm install connect-cloudant-store
Using the CloudantStore express-session storage:
var session = ;var CloudantStore = session;// example for local instance of cloudant - required params// database 'sessions' needs to be created prior to usagevar store =url: '';store;store;store;app;
Standard usage for Bluemix (public) environment :
var store =instanceName: 'myCloudantServiceName'vcapServices: JSON;app;
Using the session auto-clean feature
The storage class has a auto-clean specific method that has to be called in your code. It could be trigger for example from a setIterval timer. It checks if there is already a view available for getting the expired sessions from store db, and if not, is trying to create it. There are related optional parameters to customize the name of the view/design, set a top limit for items deleted per cleanup call.
Bellow is an example of creating an instance with the full list of parameters (default values highlighted):
var store =// connector specific parametersclient: null // new Cloudant(options)database: 'sessions'prefix: 'sess'ttl: 86400disableTTLRefresh: falsedbViewName: 'express_expired_sessions'dbDesignName: 'expired_sessions'dbRemoveExpMax: 100// Cloudant() parameters used if 'client' is not providedurl: undefinedinstanceName: undefinedvcapServices: undefined;
Allows to create the Cloudant client based on the url (containing credentials)
Can be used for working on a dev environment (ex: docker cloudant-developer)
vcapServices && instanceName
Allows to create the Cloudant client based on vcapServices JSON entry for your application and the name of the instance.
Note: This will not work on Bluemix Dedicated because cloudant library is not searching by service name first, but instead by service type key first and second by service name (instanceName);
You can use directly a cfenv npm module to get a working Cloudant url by service name:
var svc = ;if svcstore =url: svcurl;
Offers the mechanism to inject an instance of Cloudant() module as the client -> replaces any of the Cloudant parameters above
session/storage time to live - overrides the session cookie maxAge value if present
Custom prefix to be appended for all session keys
Set a different database as the session database - needs to be created prior to the connector usage.
Disable the session storage TTL automatical refresh by disabling the "touch" method, in order to reduce the number of requests to Cloudant and the risk of conflicts. As a result the session will have a fixed duration from creation (of either the .ttl param or of the session.cookie.maxAge)
Name of the expired session view to be used for building the expired sessions list
Name of the couch db design name to be used for building the expired sessions list - if the design and the view is not found in the cloudant database, the first call to store.cleanupExpired() will try to create it.
Limits the maximum amount of sessions to be bulk deleted per each store.cleanupExpired() call.
export DEBUG=connect:cloudant-store# then run your Node.js applicationnpm start
For Bluemix - use the manifest.yml file to inject the ENV variable:
# ...env:DEBUG: connect:cloudant-storeservices:- my-cloudant-service
PR code needs to pass the eslint check and unit test
PR code should have UT associated with a good coverage
npm run coverage
- The connect-cloudant-store code is inspired from from other express-session storage libraries as: connect-redis.