Getting started
The Node.js SDK runs on your server, on Node.js 20 or later.
To send your first event, install posthog-node, create one client with your project token and host from your project settings, and call capture with a distinctId and an event name.
The client queues events and sends them in batches, so call shutdown before your process exits, or the last events are lost.
Install
1npm install posthog-node@~6.0
Initialize
1import { PostHog } from 'posthog-node'
2
3const client = new PostHog('<ph_project_api_key>', { host: 'https://us.i.posthog.com' })
Capture an event
1client.capture({ distinctId: 'user_123', event: 'signed_up', properties: { plan: 'pro' } })
Shut down
Flush queued events before the process exits.
1await client.shutdown()