Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@rudderstack/rudder-sdk-node
Advanced tools
Readme
The Customer Data Platform for Developers
Website · Documentation · Community Slack
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.
Run the following command to install the Node.js SDK via npm:
$ npm install @rudderstack/rudder-sdk-node
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');
const client = new Analytics(WRITE_KEY, {
dataPlaneUrl: DATA_PLANE_URL, // default: https://hosted.rudderlabs.com
});
Below parameters are optional and can be passed during SDK initialization.
Name | Type | Default value | Description |
---|---|---|---|
dataPlaneUrl | String | https://hosted.rudderlabs.com | The data plane URL. |
path | String | /v1/batch | Path to batch endpoint. |
flushAt | Number | 20 | The number of events to be flushed when reached this limit. |
flushInterval | Number | 10000 | The maximum timespan (in milliseconds) after which the events from the in-memory queue is flushed |
maxQueueSize | Number | 460800(500kb) | Maximum payload size of a batch request |
maxInternalQueueSize | Number | 20000 | The maximum length of the in-memory queue |
logLevel | String | 'info' | Log level. Ex: 'debug', 'error' |
axiosConfig | Object | N/A | Axios config |
axiosInstance | Object | N/A | Axios instance |
axiosRetryConfig | Object | N/A | Axios retry configuration |
retryCount | Number | 3 | Number of times requests will be retried by axios if failed |
errorHandler | Function | N/A | A function that will be called if request to server failed |
gzip | Boolean | true | Whether to compress request with gzip or not |
Refer to the SDK documentation for more information on the supported calls.
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",
{
dataPlaneUrl: DATA_PLANE_URL // default: https://hosted.rudderlabs.com with default path set to /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
createPersistenceQueue
after initializing the SDK, the SDK will not implement data persistence.
Read the detailed documentation for more information on createPersistenceQueue
and the other configurable parameters.
For more information on how the event flow occurs with data persistence enabled, refer to the documentation.
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.
FAQs
Rudder Node SDK
The npm package @rudderstack/rudder-sdk-node receives a total of 42,764 weekly downloads. As such, @rudderstack/rudder-sdk-node popularity was classified as popular.
We found that @rudderstack/rudder-sdk-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.