{"id":22551742,"url":"https://github.com/orbit-apps/node-featureflags","last_synced_at":"2025-03-28T10:13:53.460Z","repository":{"id":48233859,"uuid":"186044331","full_name":"orbit-apps/node-featureflags","owner":"orbit-apps","description":"A small wrapper to query LaunchDarkly feature flags for our Node.js apps.","archived":false,"fork":false,"pushed_at":"2022-12-16T14:47:53.000Z","size":54,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-02-02T10:42:44.153Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orbit-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-10T19:34:45.000Z","updated_at":"2021-10-13T16:14:38.000Z","dependencies_parsed_at":"2022-09-21T04:01:32.926Z","dependency_job_id":null,"html_url":"https://github.com/orbit-apps/node-featureflags","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Fnode-featureflags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Fnode-featureflags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Fnode-featureflags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Fnode-featureflags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orbit-apps","download_url":"https://codeload.github.com/orbit-apps/node-featureflags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246009071,"owners_count":20708881,"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":["library"],"created_at":"2024-12-07T17:14:08.514Z","updated_at":"2025-03-28T10:13:53.438Z","avatar_url":"https://github.com/orbit-apps.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js Feature flags\n\n## Usage\n\n### Environment\n\nYou'll need a `LAUNCHDARKLY_SDK` environment variable configured, otherwise all\nflag queries will return false by default.\n\n### Setup\n\nFirst, import and initialize the library somewhere early in the app:\n\n```js\nconst { logger } = require(\"./some/logging/lib\");\nconst featureflags = require(\"node-featureflags\");\n\nfeatureflags.initialize({ logger });\n```\n\nThe only option so far is to pass an (optional) logging tool that you'd like the\nlibrary to use.\n\n### Querying a single flag\n\nTo query a single flag for a user, use `isEnabled`:\n\n```js\nconst { isEnabled } = require(\"node-featureflags\");\n\nconst user = {\n  key: \"fancy-pants-store\",\n  email: \"hans@fancy-pants-store.com\",\n  custom: {\n    groups: [\"shop\"]\n  }\n};\n\nconst userGetsFeature = await isEnabled(\"feature-something\", user);\n```\n\n### Querying all flags\n\nTo get an object of all flags for a user and their values, use `getAllFlags`:\n\n```js\nconst { getAllFlags } = require(\"node-featureflags\");\n\nconst flagsForUser = await getAllFlags(user);\n\n/*\n  {\n    'feature-something': true,\n    'feature-another': false,\n  }\n*/\n```\n\nThe `user` argument in both cases should match the shape of LaumchDarkly's user\nobject,\n[documented here](https://docs.launchdarkly.com/docs/node-sdk-reference#section-users).\n\nBoth `isEnabled` and `getAllFlags` return promises, and should be called with\n`await`.\n\n## Mocking\n\nThis package includes a mocked version of the module, intended for use with\nJest's\n[node module mocking](https://jestjs.io/docs/en/manual-mocks#mocking-node-modules).\n\nIn the root of your project, add a file at `__mocks__/node-featureflags.js`.\nImport, and then re-export, the mock version of the module:\n\n```js\nconst mockModule = require(\"node-featureflags/mock\");\n\nmodule.exports = mockModule;\n```\n\nIf using Jest, the feature flag library will be automatically mocked, with all\nflags returning `false`. To declare the value of a specific flag when running\ntests, importing the module and use the `forceFlag` method:\n\n```js\nconst featureFlags = require(\"node-featureflags\");\n\nit(\"has feature-a enabled\", () =\u003e {\n  featureFlags.forceFlag(\"feature-a\", true);\n\n  // Any queries for 'feature-a' in your code will return true\n});\n```\n\nBecause the feature flag library is a singleton, we'll need to reset the values\nof our forced flags so tests don't conflict with each other:\n\n```js\nbeforeEach(() =\u003e {\n  featureFlags.reset();\n});\n```\n\nYou can also pass an object of flags to `reset`:\n\n```js\nconst flags = {\n  featureA: \"feature-a\",\n  featureB: \"feature-b\",\n  featureC: \"feature-c\"\n};\n\nbeforeEach(() =\u003e {\n  featureFlags.reset(flags);\n});\n```\n\nThis will set the value of each flag to `false`, which may be useful when\nmocking `getAllFlags`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbit-apps%2Fnode-featureflags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forbit-apps%2Fnode-featureflags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbit-apps%2Fnode-featureflags/lists"}