2
2
3
3
[ ![ Unleash node SDK on npm] ( https://img.shields.io/npm/v/unleash-client )] ( https://www.npmjs.com/package/unleash-client )
4
4
![ npm downloads] ( https://img.shields.io/npm/dm/unleash-client )
5
- [ ![ Build Status] ( https://github.com/Unleash/unleash-client-node/workflows/Build /badge.svg )] ( https://github.com/Unleash/unleash-client-node/actions )
5
+ [ ![ Build Status] ( https://github.com/Unleash/unleash-client-node/actions/ workflows/build-and-test.yaml /badge.svg )] ( https://github.com/Unleash/unleash-client-node/actions )
6
6
[ ![ Code Climate] ( https://codeclimate.com/github/Unleash/unleash-client-node/badges/gpa.svg )] ( https://codeclimate.com/github/Unleash/unleash-client-node )
7
7
[ ![ Coverage Status] ( https://coveralls.io/repos/github/Unleash/unleash-client-node/badge.svg?branch=main )] ( https://coveralls.io/github/Unleash/unleash-client-node?branch=main )
8
8
9
- The official Unleash client SDK for Node.js.
9
+ Unleash is a private, secure, and scalable [ feature management platform] ( https://www.getunleash.io/ ) built to reduce the risk of releasing new features and accelerate software development. This server-side Node.js SDK is designed to help you integrate with Unleash and evaluate feature flags inside your application.
10
+
11
+ You can use this client with [ Unleash Enterprise] ( https://www.getunleash.io/pricing?utm_source=readme&utm_medium=nodejs ) or [ Unleash Open Source] ( https://github.com/Unleash/unleash ) .
12
+
10
13
11
14
## Getting started
12
15
@@ -31,7 +34,7 @@ is asynchronous, but if you need it to be synchronous, you can
31
34
[ block until the SDK has synchronized with the server] ( #synchronous-initialization ) .
32
35
33
36
Note that until the SDK has synchronized with the API, all features will evaluate to ` false ` unless
34
- you a [ bootstrapped configuration] ( #bootstrap ) .
37
+ you have a [ bootstrapped configuration] ( #bootstrap ) .
35
38
36
39
---
37
40
@@ -118,7 +121,7 @@ const unleash = await startUnleash({
118
121
customHeaders: { Authorization: ' <YOUR_API_TOKEN>' },
119
122
});
120
123
121
- // Unleash SDK has now fresh state from the unleash-api
124
+ // The Unleash SDK now has a fresh state from the Unleash API
122
125
const isEnabled = unleash .isEnabled (' Demo' );
123
126
```
124
127
@@ -142,8 +145,8 @@ setInterval(() => {
142
145
```
143
146
144
147
👀 ** Note** : In this example, we've wrapped the ` isEnabled ` call inside a ` setInterval ` function. In
145
- the event that all your app does is to start the SDK and check a feature status, this is will keep a
146
- node app running until the SDK has synchronized with the Unleash API. It is ** not** required in
148
+ the event that all your app does is start the SDK and check a feature status, this setup ensures that the
149
+ node app keeps running until the SDK has synchronized with the Unleash API. It is ** not** required in
147
150
normal apps.
148
151
149
152
#### Check variants
@@ -187,17 +190,17 @@ const enabled = unleash.isEnabled('someToggle', unleashContext);
187
190
188
191
### 4. Stop unleash
189
192
190
- To shut down the client (turn off the polling) you can simply call the destroy- method. This is
193
+ To shut down the client (turn off the polling) you can simply call the ` destroy ` method. This is
191
194
typically not required.
192
195
193
196
``` js
194
197
import { destroy } from ' unleash-client' ;
195
198
destroy ();
196
199
```
197
200
198
- ### Built in activation strategies
201
+ ### Built- in activation strategies
199
202
200
- The client comes supports all built-in activation strategies provided by Unleash.
203
+ The client supports all built-in activation strategies provided by Unleash.
201
204
202
205
Read more about
203
206
[ activation strategies in the official docs] ( https://docs.getunleash.io/reference/activation-strategies ) .
@@ -233,20 +236,19 @@ The initialize method takes the following arguments:
233
236
- ** strategies** - Custom activation strategies to be used.
234
237
- ** disableMetrics** - Disable metrics.
235
238
- ** customHeaders** - Provide a map(object) of custom headers to be sent to the unleash-server.
236
- - ** customHeadersFunction** - Provide a function that return a Promise resolving as custom headers
239
+ - ** customHeadersFunction** - Provide a function that returns a Promise resolving as custom headers
237
240
to be sent to unleash-server. When options are set, this will take precedence over ` customHeaders `
238
241
option.
239
242
- ** timeout** - Specify a timeout in milliseconds for outgoing HTTP requests. Defaults to 10000ms.
240
243
- ** repository** - Provide a custom repository implementation to manage the underlying data.
241
- - ** httpOptions** - Provide custom http options such as ` rejectUnauthorized ` - be careful with these
244
+ - ** httpOptions** - Provide custom HTTP options such as ` rejectUnauthorized ` - be careful with these
242
245
options as they may compromise your application security.
243
246
- ** namePrefix** - Only fetch feature toggles with the provided name prefix.
244
- - ** tags** - Only fetch feature toggles tagged with the list of tags. E.g.:
245
- ` [{type: 'simple', value: 'proxy'}] ` .
247
+ - ** tags** - Only fetch feature toggles tagged with the list of tags, such as: ` [{type: 'simple', value: 'proxy'}] ` .
246
248
247
249
## Custom strategies
248
250
249
- ### 1. implement the custom strategy:
251
+ ### 1. Implement the custom strategy
250
252
251
253
``` js
252
254
import { initialize , Strategy } from ' unleash-client' ;
@@ -261,7 +263,7 @@ class ActiveForUserWithEmailStrategy extends Strategy {
261
263
}
262
264
```
263
265
264
- ### 2. register your custom strategy:
266
+ ### 2. Register your custom strategy
265
267
266
268
``` js
267
269
initialize ({
@@ -281,13 +283,13 @@ The unleash instance object implements the EventEmitter class and **emits** the
281
283
| ------------ | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
282
284
| ready | - | is emitted once the fs-cache is ready. if no cache file exists it will still be emitted. The client is ready to use, but might not have synchronized with the Unleash API yet. This means the SDK still can operate on stale configurations. |
283
285
| synchronized | - | is emitted when the SDK has successfully synchronized with the Unleash API, or when it has been bootstrapped, and has all the latest feature toggle configuration available. |
284
- | registered | - | is emitted after the app has been registered at the api server |
286
+ | registered | - | is emitted after the app has been registered at the API server |
285
287
| sent | ` object ` data | key/value pair of delivered metrics |
286
288
| count | ` string ` name, ` boolean ` enabled | is emitted when a feature is evaluated |
287
289
| warn | ` string ` msg | is emitted on a warning |
288
- | error | ` Error ` err | is emitted on a error |
290
+ | error | ` Error ` err | is emitted on an error |
289
291
| unchanged | - | is emitted each time the client gets new toggle state from server, but nothing has changed |
290
- | changed | ` object ` data | is emitted each time the client gets new toggle state from server and changes has been made |
292
+ | changed | ` object ` data | is emitted each time the client gets new toggle state from server and changes have been made |
291
293
| impression | ` object ` data | is emitted for every user impression (isEnabled / getVariant) |
292
294
293
295
Example usage:
@@ -310,8 +312,8 @@ unleash.on('error', console.error);
310
312
unleash .on (' warn' , console .warn );
311
313
312
314
unleash .once (' registered' , () => {
313
- // Do something after the client has registered with the server api .
314
- // NB! It might not have received updated feature toggles yet.
315
+ // Do something after the client has registered with the server API .
316
+ // Note: it might not have received updated feature toggles yet.
315
317
});
316
318
317
319
unleash .once (' changed' , () => {
@@ -323,15 +325,15 @@ unleash.on('count', (name, enabled) => console.log(`isEnabled(${name})`));
323
325
324
326
## Bootstrap
325
327
326
- ( Available from v3.11.x)
328
+ > Available from v3.11.x
327
329
328
330
The Node.js SDK supports a bootstrap parameter, allowing you to load the initial feature toggle
329
331
configuration from somewhere else than the Unleash API. The bootstrap ` data ` can be provided as an
330
- argument directly to the SDK, as a ` filePath ` to load or as a ` url ` to fetch the content from.
332
+ argument directly to the SDK, as a ` filePath ` to load, or as a ` url ` to fetch the content from.
331
333
Bootstrap is a convenient way to increase resilience, where the SDK can still load fresh toggle
332
334
configuration from the bootstrap location, even if the Unleash API should be unavailable at startup.
333
335
334
- ** 1. Bootstrap with data passed as an argument**
336
+ ### 1. Bootstrap with data passed as an argument
335
337
336
338
``` js
337
339
const client = initialize ({
@@ -355,7 +357,7 @@ const client = initialize({
355
357
});
356
358
```
357
359
358
- ** 2. Bootstrap via a URL**
360
+ ### 2. Bootstrap via a URL
359
361
360
362
``` js
361
363
const client = initialize ({
@@ -371,7 +373,7 @@ const client = initialize({
371
373
});
372
374
```
373
375
374
- ** 3. Bootstrap from a File **
376
+ ### 3. Bootstrap from a file
375
377
376
378
``` js
377
379
const client = initialize ({
@@ -406,16 +408,16 @@ const featureToggleX = getFeatureToggleDefinition('app.ToggleX');
406
408
const featureToggles = getFeatureToggleDefinitions ();
407
409
```
408
410
409
- ## Custom Store Provider
411
+ ## Custom store provider
410
412
411
413
(Available from v3.11.x)
412
414
413
- By default this SDK will use a store provider that writes a backup of the feature toggle
415
+ By default, this SDK will use a store provider that writes a backup of the feature toggle
414
416
configuration to a ** file on disk** . This happens every time it receives updated configuration from
415
417
the Unleash API. You can swap out the store provider with either the provided in-memory store
416
418
provider or a custom store provider implemented by you.
417
419
418
- ** 1. Use InMemStorageProvider**
420
+ ### 1. Use ` InMemStorageProvider `
419
421
420
422
``` js
421
423
import { initialize , InMemStorageProvider } from ' unleash-client' ;
@@ -428,7 +430,7 @@ const client = initialize({
428
430
});
429
431
```
430
432
431
- ** 2. Custom Store Provider backed by redis **
433
+ ### 2. Custom store provider backed by Redis
432
434
433
435
``` js
434
436
import { initialize , InMemStorageProvider } from ' unleash-client' ;
@@ -461,17 +463,17 @@ const client = initialize({
461
463
462
464
## Custom repository
463
465
464
- You can manage the underlying data layer yourself if you want to. This enables you to use unleash
465
- offline, from a browser environment or implement your own caching layer. See
466
+ You can manage the underlying data layer yourself if you want to. This enables you to use Unleash
467
+ offline, from a browser environment, or by implement your own caching layer. See
466
468
[ example] ( examples/custom_repository.js ) .
467
469
468
470
Unleash depends on a ` ready ` event of the repository you pass in. Be sure that you emit the event
469
- ** after** you've initialized unleash .
471
+ ** after** you've initialized Unleash .
470
472
471
473
## Usage with HTTP and HTTPS proxies
472
474
473
475
You can connect to the Unleash API through the corporate proxy by setting one of the environment
474
- variables: ` HTTP_PROXY ` or ` HTTPS_PROXY `
476
+ variables: ` HTTP_PROXY ` or ` HTTPS_PROXY ` .
475
477
476
478
## Design philosophy
477
479
0 commit comments