NotificationAPI Node.js Server SDK

2.8.0 · active · verified Sun Apr 19

The NotificationAPI Node.js Server SDK provides a streamlined interface for integrating real-time and multi-channel notifications into server-side applications. This SDK allows developers to send various types of notifications, including in-app, email, SMS, and push notifications, by interacting with the NotificationAPI platform. Currently at version 2.8.0, the package appears to be actively maintained with frequent updates, indicated by its publishing history on npm. It abstracts the complexity of notification delivery, enabling developers to focus on application logic rather than the intricacies of different communication channels or provider APIs. The SDK ships with built-in TypeScript types, ensuring a robust development experience and improved code quality for TypeScript users. Key differentiators lie in the comprehensive notification platform it connects to, offering a centralized solution for notification management, templating, and delivery across multiple channels.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing the NotificationAPI SDK with environment variables and sending a basic welcome notification to a user with merge tags.

import { NotificationAPI } from 'notificationapi-node-server-sdk';

const CLIENT_ID = process.env.NOTIFICATIONAPI_CLIENT_ID ?? '';
const CLIENT_SECRET = process.env.NOTIFICATIONAPI_CLIENT_SECRET ?? '';

if (!CLIENT_ID || !CLIENT_SECRET) {
  console.error('Environment variables NOTIFICATIONAPI_CLIENT_ID and NOTIFICATIONAPI_CLIENT_SECRET must be set.');
  process.exit(1);
}

const notificationapi = new NotificationAPI({
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
});

async function sendExampleNotification() {
  try {
    const response = await notificationapi.send({
      notificationId: 'user_welcome',
      user: {
        id: 'test-user-123',
        email: 'test@example.com',
        // Additional user properties like 'name', 'phone_number' can be added
      },
      mergeTags: {
        firstName: 'John',
        lastName: 'Doe',
        welcomeMessage: 'Welcome to our service!',
      },
    });
    console.log('Notification sent successfully:', response);
  } catch (error) {
    console.error('Failed to send notification:', error);
  }
}

sendExampleNotification();

view raw JSON →