
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
#Sheldon
Bringing the fun and power of flags to your application
##Overview
Sheldon is a feature flag client wrapped around a Redis database. It is designed to handle multiple services and environments for a microservice architecture, while being fairly agnostic about what type of flag you want to keep.
##Installation
npm install sheldon --save
##Use
const Sheldon = require('sheldon');
const sheldonOptions = {
redisConnectionString: 'redis://:PASSYWORDY@redis.redis.com:10101',
appName: 'my-amazing-app-live',
defaults: {
'partyTime': 'on'
}
};
const feature = new Sheldon(sheldonOptions);
feature.readAndStartWatching();
if (feature.flag('partyTime') === 'on') {
console.log('start the party!');
} else {
console.log('no party yet');
}
##Options
new Sheldon()
takes an options object with the following fields:
redisConnectionString
[required]: the connection string to the Redis database. This can also be a path to a json file for local dev, see below.appName
[required]: the unique identifier for the application. I.e.
my-app-ci
, or great-service-qa
pollInterval
[optional]: the poll interval for Sheldon to poll the Redis
database. Defaults to 15 seconds.defaults
[required]: Used when application starts (or restarted) and redis can't be reached. Note that if you dont define all your flags the flag
function will return an error for unrecognised flags.logger
[required]: Used for logging instead of the console.log (./specs/helpers.js)[see the methods required for logger]statsd
[required]: Used to capture metrics around the redis connection for now##API
readAndStartWatching()
Reads the current flag states stored in the Redis database for the given appName
and starts polling at the pollInterval
interval.
flag(String)
=> String
Takes a flag name (a String) and returns its value (also a String - JavaScript,
eh?)
##Recommended uses
We'd recommend flagging on a match to a string, as in flag === 'on'
and having
the "safe" setting being the inverse (to guard against typos).
##Adding, Updating and Deleting flags
Writing to underlying the Redis database is not handled by Sheldon. Sheldon
reads a hash stored at the key of appName
, and reads in the fields and values
as the flags and settings respectively. To update, add and delete flags we'd
recommend using the Redis command line tool (redis-cli
), using HSET
and HGET
to set and get the value of individual flags, and
HDEL
to delete them.
##Local JSON file for dev
If the redisConnectionString
is specified as a file url, e.g. file://./sheldon-override.json
then it will read flags from that json file instead. If json document should be formatted as an object
with a key for the name of the application. That key should point to an object that contains the flags.
E.g. if the application name is 'my-test-app' and you want to set the flag 'cool-stuff' to 'on' and 'old-stuff' to 'off':
{
"my-test-app": {
"cool-stuff": "on",
"old-stuff": "off"
}
}
##Contributing Feel free to open a pull request.
FAQs
Fun with (feature) flags!
We found that sheldon demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.