> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zixflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js-Specific Features

> Node.js-Specific Features — Zixflow JavaScript SDK integration guide.

### Event Batching

The Node.js SDK automatically batches events for efficiency:

```javascript theme={null}
const analytics = new Analytics({
  writeKey: 'YOUR_API_KEY',
  maxEventsInBatch: 15,  // Default: 15 events per batch
  flushInterval: 10000    // Default: 10 seconds
})
```

### Flushing Events

Ensure all events are sent before application exit:

```javascript theme={null}
// Flush all pending events
await analytics.closeAndFlush()

// With timeout
await analytics.closeAndFlush({ timeout: 5000 })

// Good practice: flush on process exit
process.on('SIGTERM', async () => {
  await analytics.closeAndFlush()
  process.exit(0)
})
```

### Error Handling

Handle errors with event emitters:

```javascript theme={null}
analytics.on('error', (err) => {
  console.error('Analytics error:', err)
})

analytics.on('http_request', (event) => {
  console.log('HTTP request:', event)
})
```

### Callbacks

Use callbacks for individual events:

```javascript theme={null}
analytics.track({
  userId: 'user@example.com',
  event: 'signup_completed'
}, (err, batch) => {
  if (err) {
    console.error('Failed to track event:', err)
  } else {
    console.log('Event tracked successfully')
  }
})
```

***
