# Server SDK installation

Source: https://pushary.com/docs/web-push/server-sdk/installation
Last updated: 2026-10-23

> Install and configure the Pushary server SDK for your backend

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](/docs/web-push/client-sdk/installation).

## Installation [#installation]

```bash
npm install @pushary/server
# or
yarn add @pushary/server
# or
pnpm add @pushary/server
# or
bun add @pushary/server
```

## Quick Start [#quick-start]

```typescript
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 [#configuration]

```typescript
interface PusharyConfig {
  apiKey: string      // Required: API key (pk_xxx.secret_xxx)
  baseUrl?: string    // Optional: Custom API URL
}
```

### API Key [#api-key]

The server SDK requires your API key:

```
pk_abc123def456.secret789xyz
```

**Important:** 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 [#environment-variables]

Store your API key securely:

```bash
# .env
PUSHARY_API_KEY=pk_xxx.secret_xxx
```

```typescript
const pushary = createPusharyServer({
  apiKey: process.env.PUSHARY_API_KEY!,
})
```

## Error Handling [#error-handling]

All methods throw on error. Handle errors appropriately:

```typescript
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 [#typescript]

The SDK is fully typed. Import types as needed:

```typescript
import {
  createPusharyServer,
  type PusharyServer,
  type Subscriber,
  type Campaign,
  type Template,
  type SendNotification,
  type SendResult,
} from '@pushary/server'
```