Node.js product analytics installation

Run either npm or yarn in terminal to add it to your project:

npm install posthog-node --save

In your app, set your project API key before making any calls.

Node.js
import { PostHog } from 'posthog-node'
const client = new PostHog(
'<ph_project_api_key>',
{ host: 'https://us.i.posthog.com' }
)
await client.shutdown()

You can find your project API key and instance address in the project settings page in PostHog.

Note: As a rule of thumb, we do not recommend hardcoding API keys. Setting it as an environment variable is preferred.

Community questions

Was this page useful?

Questions about this page? or post a community question.