Package Exports
- @rudderstack/rudder-sdk-node
- @rudderstack/rudder-sdk-node/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rudderstack/rudder-sdk-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
The Customer Data Platform for Developers
Website · Documentation · Community Slack
RudderStack Node.js SDK
The RudderStack Node.js SDK lets you track your customer event data from your Node.js applications and send it to your specified destinations.
Refer to the documentation for more details.
Installing the SDK
Run the following command to install the Node.js SDK via npm:
$ npm install @rudderstack/rudder-sdk-nodeUsing the SDK
To create a global RudderStack client object and use it for the subsequent event calls, run the following snippet:
const Analytics = require("@rudderstack/rudder-sdk-node");
// we need the batch endpoint of the Rudder server you are running
const client = new Analytics(WRITE_KEY, DATA_PLANE_URL/v1/batch");Supported calls
Refer to the SDK documentation for more information on the supported calls.
Initializing the SDK for data persistence
This is a beta feature. Contact us on our Community Slack in case you face any issues.
RudderStack has a data persistence feature to persist the events in Redis, leading to better event delivery guarantees. Also, the SDK can retry event delivery multiple times as the queue is maintained in a different process space(Redis).
| To use this feature, you will need to host a Redis server and use it as the intermediary data storage queue. |
|---|
A sample SDK initialization is shown below:
const client = new Analytics(
"write_key",
"server_url/v1/batch",
{
flushAt: <number> = 20,
flushInterval: <ms> = 20000
maxInternalQueueSize: <number> = 20000 // the max number of elements that the SDK can hold in memory,
// this is different than the Redis list created when persistence is enabled
}
);
client.createPersistenceQueue({ redisOpts: { host: "localhost" } }, err => {})To initialize the data persistence queue, you need to call the createPersistenceQueue method which takes two parameters as input - queueOpts and a callback. The createPersistenceQueue method will initialize a Redis list by calling Bull's utility methods.
If you do not call
createPersistenceQueueafter initializing the SDK, the SDK will not implement data persistence.
Read the detailed documentation for more information on createPersistenceQueue and the other configurable parameters.
Event flow
For more information on how the event flow occurs with data persistence enabled, refer to the documentation.
Limitations around data persistence
- Refer to this page to understand the limitations
- For more details on the limitations, read: https://redis.io/topics/cluster-tutorial#redis-cluster-data-sharding
- As a workaround, refer to this page: https://gitter.im/OptimalBits/bull/archives/2018/04/17. We pass a prefix with default value as {rudder}.
Contact us
If you come across any issues while configuring or using the RudderStack Node.js SDK, you can contact us or start a conversation in our Slack community.