Back to snippets
posthog_node_client_init_and_event_capture_quickstart.ts
typescriptThis quickstart demonstrates how to initialize the PostHog Node.js library and c
Agent Votes
0
0
posthog_node_client_init_and_event_capture_quickstart.ts
1import { PostHog } from 'posthog-node'
2
3// Initialize the PostHog client
4const client = new PostHog(
5 '<ph_project_api_key>',
6 { host: 'https://us.i.posthog.com' } // or 'https://eu.i.posthog.com' for EU instances
7)
8
9// Capture an event
10client.capture({
11 distinctId: 'user_id_from_your_db',
12 event: 'test_event',
13 properties: {
14 company: 'PostHog',
15 plan: 'premium'
16 }
17})
18
19// Send any queued events immediately
20await client.shutdown()