API reference for the @novu/js package

Complete API reference for the Novu JavaScript package

Novu

The Novu client provides methods to interact with notifications, preferences, and real-time events.

Constructor Options

---type-table--- ../types/js-types.ts#NovuOptions ---end---

Usage

import { Novu } from "@novu/js";
 
const novu = new Novu({
  subscriberId: "SUBSCRIBER_ID",
  applicationIdentifier: "APPLICATION_IDENTIFIER",
});

Notifications

Methods

list

Fetches a list of notifications based on provided filters.

---type-table--- ../types/js-types.ts#NotificationFilter ---end---

const notifications = await novu.notifications.list({
  limit: 30,
  read: false,
  archived: false,
  tags: ['tag1', 'tag2'],
  offset: 0,
});

The response will be of type:

---type-table--- ../types/js-types.ts#NotificationsResponse ---end---

count

Fetches the count of notifications based on filters.

---type-table--- ../types/js-types.ts#NotificationFilter ---end---

// Single filter
const count = await novu.notifications.count({
  read: false,
  archived: false,
});

read

Marks a notification as read.

await novu.notifications.read({ notificationId: 'NOTIFICATION_ID' });

unread

Marks a notification as unread.

await novu.notifications.unread({ notificationId: 'NOTIFICATION_ID' });

archive

Archives a notification.

await novu.notifications.archive({ notificationId: 'NOTIFICATION_ID' });

unarchive

Unarchives a notification.

await novu.notifications.unarchive({ notificationId: 'NOTIFICATION_ID' });

readAll

Marks all notifications as read. Can be filtered by tags.

await novu.notifications.readAll({
  tags: ['tag1', 'tag2'],
});

archiveAll

Archives all notifications. Can be filtered by tags.

await novu.notifications.archiveAll({
  tags: ['tag1', 'tag2'],
});

archiveAllRead

Archives all read notifications. Can be filtered by tags.

await novu.notifications.archiveAllRead({
  tags: ['tag1', 'tag2'],
});

completePrimary

Marks primary action of a notification as completed.

await novu.notifications.completePrimary({ notificationId: 'NOTIFICATION_ID' });

completeSecondary

Marks secondary action of a notification as completed.

await novu.notifications.completeSecondary({ notificationId: 'NOTIFICATION_ID' });

revertPrimary

Reverts primary action of a notification to pending.

await novu.notifications.revertPrimary({ notificationId: 'NOTIFICATION_ID' });

revertSecondary

Reverts secondary action of a notification to pending.

await novu.notifications.revertSecondary({ notificationId: 'NOTIFICATION_ID' });

Preferences

Methods

list

Fetches the subscriber's notification preferences.

const preferences = await novu.preferences.list();

The response will be of type:

---type-table--- ../types/js-types.ts#PreferenceResponse ---end---

Events

The Novu client provides real-time event handling through WebSocket connections.

Available Events

  • notifications.notification_received: Triggered when a new notification is received
  • notifications.unread_count_changed: Triggered when the unread count changes

Usage

novu.on('notifications.notification_received', (data) => {
  console.log('New notification:', data);
});
 
novu.on('notifications.unread_count_changed', (data) => {
  console.log('Unread count:', data);
});

Types

Notification

---type-table--- ../types/js-types.ts#Notification ---end---

Action

---type-table--- ../types/js-types.ts#Action ---end---

NotificationButton

---type-table--- ../types/js-types.ts#NotificationButton ---end---

Subscriber

---type-table--- ../types/js-types.ts#Subscriber ---end---

On this page