> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Hono Error Tracking installation Canonical URL: https://posthog.com/docs/error-tracking/installation/hono > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.i.posthog.com` instead of `https://us.i.posthog.com` (ingestion host), and use `https://eu.posthog.com` instead of `https://app.posthog.com` (app host for links). ## On this page - [Install the package](#install-the-package) - [Initialize PostHog](#initialize-posthog) - [Send an event](#send-an-event) - [Exception handling example](#exception-handling-example) - [Verify error tracking](#verify-error-tracking) - [Upload source maps](#upload-source-maps) 1. 1 ## Install the package Required Install the PostHog Node.js library using your package manager: ### npm ```bash npm install posthog-node@5 ``` ### yarn ```bash yarn add posthog-node@5 ``` ### pnpm ```bash pnpm add posthog-node@5 ``` ### bun ```bash bun add posthog-node@5 ``` 2. 2 ## Initialize PostHog Required Initialize the PostHog client with your project token: Node.js ```javascript import { PostHog } from 'posthog-node' const client = new PostHog( '', { host: 'https://us.i.posthog.com' } ) ``` 3. 3 ## Send an event Recommended Once installed, you can manually send events to test your integration: Node.js ```javascript client.capture({ distinctId: 'distinct_id_of_the_user', event: 'event_name', properties: { property1: 'value', property2: 'value', }, }) // The client sends events in batches. Call shutdown() before the process // exits so that queued events are sent. In a long-running server, call it // once when the server stops. await client.shutdown() ``` 4. 4 ## Exception handling example Required Hono uses [`app.onError`](https://hono.dev/docs/api/exception#handling-httpexception) to handle uncaught exceptions. You can take advantage of this for error tracking. Remember to **export** your [project token](https://app.posthog.com/settings/project#variables) as an environment variable. index.ts ```typescript import { PostHog } from 'posthog-node' const posthog = new PostHog(process.env.POSTHOG_TOKEN, { host: 'https://us.i.posthog.com' }) app.onError(async (err, c) => { posthog.captureException(err, 'user_distinct_id_with_err_rethrow', { path: c.req.path, method: c.req.method, url: c.req.url, headers: c.req.header(), // ... other properties }) await posthog.flush() // other error handling logic return c.text('Internal Server Error', 500) }) ``` 5. ## Verify error tracking Recommended *Confirm events are being sent to PostHog* Before proceeding, let's make sure exception events are being captured and sent to PostHog. You should see events appear in the activity feed. ![Activity feed with events](https://res.cloudinary.com/dmukukwp6/image/upload/SCR_20250729_ouxl_f788dd8cd2.png) [Check for exceptions in PostHog](https://app.posthog.com/activity/explore) 6. 5 ## Upload source maps Required Great, you're capturing exceptions! If you serve minified bundles, the next step is to upload source maps to generate accurate stack traces. Let's continue to the next section. [Upload source maps](https://posthog.com/docs/error-tracking/upload-source-maps.md)