{"id":18948799,"url":"https://github.com/creditkarma/feature-flags","last_synced_at":"2025-04-15T23:31:01.665Z","repository":{"id":35764298,"uuid":"135329445","full_name":"creditkarma/feature-flags","owner":"creditkarma","description":"A dynamic feature flags library for Node.js","archived":false,"fork":false,"pushed_at":"2023-04-23T22:14:19.000Z","size":377,"stargazers_count":50,"open_issues_count":9,"forks_count":6,"subscribers_count":14,"default_branch":"master","last_synced_at":"2023-09-15T17:19:27.101Z","etag":null,"topics":["feature-flags","microservices","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creditkarma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-29T17:17:57.000Z","updated_at":"2023-08-07T20:11:09.000Z","dependencies_parsed_at":"2023-01-16T05:44:40.911Z","dependency_job_id":null,"html_url":"https://github.com/creditkarma/feature-flags","commit_stats":null,"previous_names":[],"tags_count":13,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creditkarma%2Ffeature-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creditkarma%2Ffeature-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creditkarma%2Ffeature-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creditkarma%2Ffeature-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creditkarma","download_url":"https://codeload.github.com/creditkarma/feature-flags/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223688661,"owners_count":17186298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["feature-flags","microservices","nodejs","typescript"],"created_at":"2024-11-08T13:14:42.866Z","updated_at":"2024-11-08T13:14:43.596Z","avatar_url":"https://github.com/creditkarma.png","language":"TypeScript","readme":"# Feature Flags\n\nA dynamic feature flags library for Node.js. This library gives you fine-grained control over rolling out and testing new features.\n\nThis implementation is largely based on [Feature Toggles](https://twitter.github.io/finagle/guide/Configuration.html#feature-toggles) in [Twitter's Finagle framework](https://github.com/twitter/finagle).\n\nFor a detail looks at feature flags check out this article [Feature Toggles](https://martinfowler.com/articles/feature-toggles.html).\n\nThe idea behind feature flags is that they give you a way for testing new code and ramping that code over time. In your configuration you would provide a description of what percentage of requests should use a particular code path and the library will somewhat randomly return a boolean for each toggle representing if it should be used on a particular request or not. Once a code path is ramped to 100% it is expected the feature flag for that code would be removed.\n\n## Install\n\nThis feature flags library has a peer dependency on `@creditkarma/dynamic-config`.\n\n```sh\n$ npm install --save @creditkarma/dynamic-config\n$ npm install --save @creditkarma/feature-flags\n```\n\n## Usage\n\nUsing feature flags is very easy. They are really just a boolean indicating which code path you should use.\n\n```typescript\nimport { toggleMap, Toggle } from '@creditkarma/feature-flags'\n\nasync function startApp(app) {\n    const toggle: Toggle = await toggleMap('com.example.service.UseNewBackend')\n\n    app.get('/test', (req, res) =\u003e {\n        if (toggle()) {\n            // Use new code path\n        } else {\n            // Use old code path\n        }\n    })\n}\n```\n\nIn application code there are only two things you need to use. The `toggleMap` function and the `Toggle` type.\n\n### `toggleMap`\n\nThe `toggleMap` is a function that returns a Promise of a toggle for a given key. Your application can have many toggles. Each of these toggles has a unique string identifier that you specify. You provide this id to the `toggleMap` function and it gives you back a `Promise\u003cToggle\u003e`. A `Toggle` is a function that just returns a `boolean`. It will return, randomly, `true` based on the configured percentage.\n\n## Configuration\n\nThe real work of the feature flag is actually the configuration. In your application config you would have a key call `toggles`. This key is expected to be at the root level of your config `JSON`:\n\n```json\n{\n    \"toggles\": {\n        \"com.example.service.UseNewBackend\" : {\n            \"description\": \"Use new backend code\",\n            \"fraction\": 0.1,\n            \"type\": \"RAMP\",\n        }\n    }\n}\n```\n\nEach `Toggle` must have an `id` and a `fraction`, the number indicating how often to return `true`. The `fraction` is a number from `0.0` to `1.0`. So in the example the value `0.1` indicates that this `Toggle` will be `true` 10% of the time it is called.\n\n### Dynamic Config\n\n[DynamicConfig](https://github.com/creditkarma/dynamic-config) is a pluggable config library for Node.js that allows for runtime changes to config values. This is the basis for our feature flags support. It certainly isn't required that you use Dyanmic Config for all of your application config, but that would be recommended.\n\nYou should check out the docs for DynamicConifg if you are going to use this library. The gist is this. DynamicConfig has plugable support for remote data stores for configuration values. These external data stores can have their values updated without having to restart the application. The feature flags library will be updated if the remote values change and the ramp of your toggles will be updated in real time.\n\nThe only time there is a performance penalty for loading the external config is during the creation of a `Toggle`. After this initial penalty updated values are loaded in the background.\n\n### Flag Schema\n\nThe schema for the `toggles` config:\n\n```json\n{\n    \"\\$schema\": \"http://json-schema.org/draft-04/schema#\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"toggles\": {\n            \"type\": \"object\",\n            \"patternProperties\": {\n                \"[A-Za-z0-9 -_.]+\": {\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"fraction\": {\n                            \"type\": \"number\",\n                            \"minimum\": 0.0,\n                            \"maximum\": 1.0,\n                        },\n                        \"type\": {\n                            \"type\": \"string\",\n                        },\n                        \"description\": {\n                            \"type\": \"string\",\n                        },\n                    },\n                    \"required\": [ \"type\", \"fraction\" ],\n                },\n            }\n        }\n    },\n    \"required\": [ \"toggles\" ]\n}\n```\n\n## Contributing\n\nFor more information about contributing new features and bug fixes, see our [Contribution Guidelines](https://github.com/creditkarma/CONTRIBUTING.md).\nExternal contributors must sign Contributor License Agreement (CLA)\n\n## License\n\nThis project is licensed under [Apache License Version 2.0](./LICENSE)\n","funding_links":[],"categories":["📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreditkarma%2Ffeature-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreditkarma%2Ffeature-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreditkarma%2Ffeature-flags/lists"}