[](https://godaddy-oss-slack.herokuapp.com/)
npm install @godaddy/split-node-serializer
Fetches split definitions and segments from Split.io and serializes them into a
set of strings that the JavaScript SDK can consume.
Install via npm:
``console`
$ npm i @godaddy/split-node-serializer --save
Use this package in your server-side Node.js environment. The serializer exposes:
1. a Poller that periodically requests raw experiment configuration data from Split.io. Requests happen in the background and the poller caches the latest data in local memory.DataSerializer
1. a that reads from the poller's cache, serializes the data, and returns it in a script to be injected into a client's HTML.
Create an instance of Poller and DataSerializer:
`js
const { Poller, DataSerializer } = require('@godaddy/split-node-serializer')
const poller = new Poller({
splitioApiKey: 'YOUR_API_KEY',
pollingRateSeconds: 600,
serializeSegments: false
})
const dataSerializer = new DataSerializer({ poller })
`
The following option properties are available to the Poller:
| Property | Description |
|-------------------------------|-------------|
| splitioApiKey | The Split.io SDK key for the environment your app is running in. (required) |
| pollingRateSeconds | The interval at which to poll Split.io. Defaults to 300 (5 minutes). |
| serializeSegments | Whether or not to fetch segment configuration data. Defaults to false. |
#### Serializing segments
Segments are pre-defined groups of customers that features can be targeted to. More info here.
Note: Requesting serialized segments will increase the size of your response. Segments can be very large if they include all company employees, for example.
#### start
Make an initial request for changes and start polling for raw configuration data
every pollingRateSeconds:
`js`
poller.start()
#### stop
To stop the poller:
`js`
poller.stop()
The poller emits an error event on errors from the Split.io API.
#### generateSerializedDataScript
generateSerializedDataScript is an async method that will read the latest data from the cache and return a scriptwindow.__splitCachePreload
that adds serialized data to the object. The
serialized data will be used to determine cohort allocations.
generateSerializedDataScript accepts the following arguments:
| Property | Description |
|-------------------------------|-------------|
| splits | Array of strings that, if included, filters the splitsData (Optional) |
| preloadLocation | The property on the window object where the data is stored. Defaults to __splitCachePreload (Optional) |
`js
const serializedDataScript = await dataSerializer.generateSerializedDataScript()
console.log(serializedDataScript)
//
`
Note: Though this is an async method, there will only be a Split.io API call if you have serializeSegments set to true and are passing in a unique splits parameter that this instance's method has not received before.
Run the linter:
`console`
$ npm run lint
Run unit tests:
`console`
$ npm test
Generate a coverage report:
`console``
$ npm run coverage