Node.js Product Analytics installation

Install with the wizard

Run this command in your project directory to add PostHog to your Node.js project. The wizard detects your framework, installs the SDK, and sets up your first events.

Learn more

Or set it up manually by following the rest of this guide.

  1. Install the package

    Required

    Install the PostHog Node.js library using your package manager:

    npm install posthog-node
  2. Initialize PostHog

    Required

    Initialize the PostHog client with your project token:

    Node.js
    import { PostHog } from 'posthog-node'
    const client = new PostHog(
    '<ph_project_token>',
    {
    host: 'https://us.i.posthog.com'
    }
    )
  3. Send an event

    Recommended

    Once installed, you can manually send events to test your integration:

    Node.js
    client.capture({
    distinctId: 'distinct_id_of_the_user',
    event: 'event_name',
    properties: {
    property1: 'value',
    property2: 'value',
    },
    })
  4. Next steps

    Recommended

    Now that you're capturing events, continue with the resources below to learn what else Product Analytics enables within the PostHog platform.

    ResourceDescription
    Capturing eventsLearn how to capture custom events beyond autocapture
    Identifying usersAssociate events with specific users
    Creating insightsBuild trends, funnels, and retention charts
    Group analyticsTrack events at the company or account level

Still have questions?

Was this page useful?