{"id":19149816,"url":"https://github.com/harness/ff-nodejs-server-sdk","last_synced_at":"2025-05-07T04:07:36.203Z","repository":{"id":37083571,"uuid":"399515540","full_name":"harness/ff-nodejs-server-sdk","owner":"harness","description":"ff-nodejs-server-sdk","archived":false,"fork":false,"pushed_at":"2025-04-04T11:25:29.000Z","size":1357,"stargazers_count":7,"open_issues_count":3,"forks_count":8,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-05-07T04:07:25.187Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/harness.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-24T15:25:21.000Z","updated_at":"2025-04-04T11:19:40.000Z","dependencies_parsed_at":"2024-01-16T15:16:03.340Z","dependency_job_id":"2eed44b6-0b85-4d68-9c4e-b75491b33ae0","html_url":"https://github.com/harness/ff-nodejs-server-sdk","commit_stats":{"total_commits":173,"total_committers":15,"mean_commits":"11.533333333333333","dds":0.5549132947976878,"last_synced_commit":"7eac4b84a413ee35e641233008c506854390ab1d"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-nodejs-server-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-nodejs-server-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-nodejs-server-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-nodejs-server-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harness","download_url":"https://codeload.github.com/harness/ff-nodejs-server-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810273,"owners_count":21807759,"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":[],"created_at":"2024-11-09T08:09:45.916Z","updated_at":"2025-05-07T04:07:36.177Z","avatar_url":"https://github.com/harness.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js SDK For Harness Feature Flags\n\n[![TypeScript version][ts-badge]][typescript-4-3]\n[![Node.js version][nodejs-badge]][nodejs]\n[![APLv2][license-badge]][license]\n\nUse this README to get started with our Feature Flags (FF) SDK for Node.js. This guide outlines the basics of getting\nstarted with the SDK and provides a full code sample for you to try out.\n\nThis sample doesn't include configuration options, for in depth steps and configuring the SDK, for example, disabling\nstreaming or using our Relay Proxy, see the [Node.js SDK Reference](https://docs.harness.io/article/3v7fclfg59-node-js-sdk-reference).\n\n## Requirements\n\nTo use this SDK, make sure you’ve:\n\n- Installed Node.js v12 or a newer version\n\nTo follow along with our test code sample, make sure you’ve:\n\n- [Created a Feature Flag on the Harness Platform](https://docs.harness.io/article/1j7pdkqh7j-create-a-feature-flag) called `harnessappdemodarkmode`\n- [Created a server SDK key](https://docs.harness.io/article/1j7pdkqh7j-create-a-feature-flag#step_3_create_an_sdk_key) and made a copy of it\n\n## Installing the SDK\n\nThe first step is to install the FF SDK as a dependency in your application. To install using npm, use:\n\n```shell\nnpm install @harnessio/ff-nodejs-server-sdk\n```\n\nOr to install with yarn, use:\n\n```shell\nyarn add @harnessio/ff-nodejs-server-sdk\n```\n\n## Code Sample\n\nThe following is a complete code example that you can use to test the `harnessappdemodarkmode` Flag you created on the\nHarness Platform. When you run the code it will:\n\n- Connect to the FF service.\n- Report the value of the Flag every 10 seconds until the connection is closed.\n- Listen for when the `harnessappdemodarkmode` Flag is toggled on or off on the Harness Platform and report the new value.\n\n```javascript\nconst { Client, Event } = require('@harnessio/ff-nodejs-server-sdk');\n\n(async () =\u003e {\n  // set apiKey to your SDK API Key\n  const apiKey = 'YOUR_FF_SDK_KEY';\n\n  // set flagName to your flag identifier from the UI\n  const flagName = 'harnessappdemodarkmode';\n\n  console.log('Harness SDK Getting Started');\n\n  // Create Client\n  const client = new Client(apiKey);\n\n  // Create a target (different targets can receive different results based on rules.\n  // Here we are including \"location\" as a custom attribute)\n  const target = {\n    identifier: 'nodeserversdk',\n    name: 'NodeServerSDK',\n    attributes: {\n      location: 'emea',\n    },\n  };\n\n  try {\n    await client.waitForInitialization();\n  } catch (e) {\n    console.log(\"Error when authenticating Feature Flags client: \" + e)\n  }\n\n  try {\n    // Log the state of the flag every 10 seconds\n    setInterval(async () =\u003e {\n      const value = await client.boolVariation(flagName, target, false);\n      console.log('Flag variation:', value);\n    }, 10000);\n\n    // We can also watch for the event when a flag changes\n    client.on(Event.CHANGED, async (flagIdentifier) =\u003e {\n      const value = await client.boolVariation(flagIdentifier, target, false);\n      console.log(`${flagIdentifier} changed: ${value}`);\n    });\n  } catch (e) {\n    console.error('Error:', e);\n  }\n})();\n```\n\n## Running the example\n\nTo run the example, execute your script:\n\n```shell\nnode example.js\n```\n\nWhen you're finished you can exit the example by stopping the process using \u003ckbd\u003econtrol\u003c/kbd\u003e-\u003ckbd\u003ec\u003c/kbd\u003e.\n\n\n## Using custom TLS certificates\n\nIf using a proxy or SMP instance that does not use a widely publicised pre-bundled CA you can provide your own CA using the `tlsTrustedCa` option.\nThis option takes a path to a file that contains a bundle of certificates in PEM format. If this option is present, the HTTP client will ignore\nany pre-bundled certs so you need to include the entire certificate chain of your custom cert.\n\n```\n  const client = new Client(apiKey, {\n    baseUrl: 'https://ffserver:8000/api/1.0',\n    eventsUrl: 'https://ffserver:8001/api/1.0',\n    tlsTrustedCa: 'path_to_cert_chain.crt',\n  });\n```\n\n## Additional Reading\n\nFor further examples and config options, see the [Node.js SDK Reference](https://docs.harness.io/article/3v7fclfg59-node-js-sdk-reference) and the [test Node.js project](https://github.com/drone/ff-nodejs-server-sdk).\nFor more information about Feature Flags, see our [Feature Flags documentation](https://docs.harness.io/article/0a2u2ppp8s-getting-started-with-feature-flags).\n\n[ts-badge]: https://img.shields.io/badge/TypeScript-4.3-blue.svg\n[nodejs-badge]: https://img.shields.io/badge/Node.js-\u003e=%2012-blue.svg\n[nodejs]: https://nodejs.org/dist/latest-v14.x/docs/api/\n[typescript]: https://www.typescriptlang.org/\n[typescript-4-3]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-3.html\n[license-badge]: https://img.shields.io/badge/license-APLv2-blue.svg\n[license]: https://github.com/drone/ff-nodejs-server-sdk/blob/main/LICENSE\n[jest]: https://facebook.github.io/jest/\n[eslint]: https://github.com/eslint/eslint\n[prettier]: https://prettier.io\n[volta]: https://volta.sh\n[gh-actions]: https://github.com/features/actions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharness%2Fff-nodejs-server-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharness%2Fff-nodejs-server-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharness%2Fff-nodejs-server-sdk/lists"}