Server SDK installation
Install and configure the Pushary server SDK for your backend
Updated
Use @pushary/server in your backend to send notifications and manage subscribers with an API key. Keep the key on your server. To subscribe visitors in the browser, use the client SDK.
Installation
npm install @pushary/server
# or
yarn add @pushary/server
# or
pnpm add @pushary/server
# or
bun add @pushary/serverQuick Start
import { createPusharyServer } from '@pushary/server'
const pushary = createPusharyServer({
apiKey: process.env.PUSHARY_API_KEY!,
})
await pushary.notifications.send({
title: 'Hello!',
body: 'Your order has shipped',
subscriberIds: ['sub_123'],
})Configuration
interface PusharyConfig {
apiKey: string // Required: API key (pk_xxx.secret_xxx)
baseUrl?: string // Optional: Custom API URL
}API Key
The server SDK requires your API key:
pk_abc123def456.secret789xyzImportant: Never expose this key in client-side code, public repositories, or browser environment variables.
Get your API key from Dashboard → Sites → Settings → Integration tab → Create API Key. The key is only shown once at creation time.
Environment Variables
Store your API key securely:
# .env
PUSHARY_API_KEY=pk_xxx.secret_xxxconst pushary = createPusharyServer({
apiKey: process.env.PUSHARY_API_KEY!,
})Error Handling
All methods throw on error. Handle errors appropriately:
try {
await pushary.notifications.send({
title: 'Hello',
body: 'World',
subscriberIds: ['sub_123'],
})
} catch (error) {
if (error instanceof Error) {
console.error('Failed to send:', error.message)
}
}TypeScript
The SDK is fully typed. Import types as needed:
import {
createPusharyServer,
type PusharyServer,
type Subscriber,
type Campaign,
type Template,
type SendNotification,
type SendResult,
} from '@pushary/server'Was this page helpful?