Event
Search…
⌃K
Links

Node.js

Use Event's Node SDK to send server-side events to various destinations.

SDK Setup Guide

Event's Node SDK lets you track and send the events from your Node applications to the specified destinations.
Refer to the Node SDK's GitHub codebase for the implementation-specific details.
Github Badge

Connecting the SDK Source

  1. 1.
    Sign up to Event Cloud
  2. 2.
    Connect a Node.js Source from the dashboard. You should be able to see the secret key for this source, as shown:
The Setup tab in the Event dashboard (seen above) has the SDK installation snippet containing the secret key. Copy it to integrate the Node SDK into your application.

Installing the Node SDK on your machine

To install the Event Node SDK using npm, run the following command:
npm install @event-inc/emit

Initializing the SDK

Run the following snippet to initialize the Node SDK. It creates a global Event client object that can be used for all the subsequent event requests.
import { createClient } from "@event-inc/emit";
// Init your Web SDK
const client = createClient(process.env.EVENT_INC_SECRET_KEY);

Sending events

Emit

The emit call lets you create and package an event with a name and a payload.
A sample emit call is as shown:
import { createClient } from "@event-inc/emit";
// Init your Web SDK
const client = createClient(process.env.EVENT_INC_SECRET_KEY);
// Emit Message
client.emit("user.created", user);
The emit parameters are described below:
Field
Required
Type
Description
Event
string
The name of the event
Payload
string
The data associated with the event
Alternatively, you can emit using cURL:
# Using cURL
curl --location --request POST 'https://stream.event.dev/emit' \
--header 'X-Buildable-Secret: <YOUR SECRET KEY 🤫>' \
--header 'Content-Type: application/json' \
--data-raw '{
"event": "user.created",
"payload": {
"name": "John Doe"
}
}'
Last modified 1mo ago