Generated banner for Feature Flags Nodejs
Generated logo for Feature Flags Nodejs

Feature Flags Nodejs

PostHogOfficialCreated by PostHog

  • Skill
  • Tool integration
  • Data and AI
  • MIT
  • No issues found

From the author

PostHog feature flags for Node.js applications
— the description by PostHog

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides guidance and best practices for implementing PostHog feature flags within Node.js environments. It covers installation, code implementation patterns, and architectural strategies to ensure efficient and reliable feature management. The skill emphasizes server-side evaluation, the use of environment variables for security, and maintaining clean code by centralizing flag logic.

What it does

  • Provides patterns for implementing boolean and multivariate feature flags in Node.js.
  • Outlines best practices for flag naming and organization to improve maintainability.
  • Advises on using server-side evaluation to prevent UI flickering.
  • Recommends strategies like reverse proxies to ensure flag reliability against ad blockers.
  • Suggests wrapping flag checks in helper functions to minimize code duplication.
  • Integrates with PostHog MCP tools for direct flag management via the agent.

When to use it

  • When you need to perform controlled feature rollouts or experiments in a Node.js backend.
  • When you want to manage feature flags programmatically rather than manually in the dashboard.
  • When you need to ensure consistent user experiences across sessions by identifying users or groups.
  • When you are looking to optimize flag evaluation performance using local evaluation techniques.

Advantages

  • Reduces code clutter by encouraging centralized flag logic.
  • Improves performance by supporting local flag evaluation.
  • Enhances security by enforcing the use of environment variables for API keys.
  • Increases reliability by providing strategies to bypass ad-blocking interference.

Usage examples

“How do I check a boolean feature flag in my Node.js service?”
The agent will provide a code snippet using the appropriate PostHog method to evaluate the flag and explain how to wrap it in a function for cleaner code.
“Can you help me create a new feature flag for my beta users?”
The agent will check for a connected PostHog MCP server and use the available tools to create the flag directly in your PostHog project.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/posthog/feature-flags-nodejs/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip feature-flags-nodejs.zip -d .agents/skills

Documentation by PostHog

PostHog feature flags for Node.js

This skill helps you add PostHog feature flags to Node.js applications.

Reference files

  • references/nodejs.md - Node.js feature flags installation - docs

  • references/adding-feature-flag-code.md - Adding feature flag code - docs

  • references/best-practices.md - Feature flag best practices - docs

Consult the documentation for API details and framework-specific patterns.

Key principles

  • Environment variables: Always use environment variables for PostHog keys. Never hardcode them.

  • Minimal changes: Add feature flag code alongside existing logic. Don't replace or restructure existing code.

  • Boolean flags first: Default to boolean flag checks unless the user specifically asks for multivariate flags.

  • Server-side when possible: Prefer server-side flag evaluation to avoid UI flicker.

PostHog MCP tools

Check if a PostHog MCP server is connected. If available, look for tools related to feature flag management (creating, listing, updating, deleting flags). Use these tools to manage flags directly in PostHog rather than requiring the user to do it manually in the dashboard.

Framework guidelines

No specific framework guidelines.

Files

references/nodejs.md

Node.js feature flags installation - Docs

  1. 1

    Install the package

    Required

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

    PostHog AI

    npm
    npm install posthog-node
    yarn
    yarn add posthog-node
    pnpm
    pnpm add posthog-node
  2. 2

    Initialize PostHog

    Required

    Initialize the PostHog client with your project token:

    Node.js

    PostHog AI

    import { PostHog } from 'posthog-node'
    const client = new PostHog(
        '<ph_project_token>',
        {
            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

    PostHog AI

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

    Evaluate boolean feature flags

    Required

    Check if a feature flag is enabled:

    const isFeatureFlagEnabled = await client.isFeatureEnabled('flag-key', 'distinct_id_of_your_user')
    if (isFeatureFlagEnabled) {
        // Your code if the flag is enabled
        // Optional: fetch the payload
        const matchedFlagPayload = await client.getFeatureFlagPayload('flag-key', 'distinct_id_of_your_user', isFeatureFlagEnabled)
    }
  5. 5

    Evaluate multivariate feature flags

    Optional

    For multivariate flags, check which variant the user has been assigned:

    const enabledVariant = await client.getFeatureFlag('flag-key', 'distinct_id_of_your_user')
    if (enabledVariant === 'variant-key') {  // replace 'variant-key' with the key of your variant
        // Do something differently for this user
        // Optional: fetch the payload
        const matchedFlagPayload = await client.getFeatureFlagPayload('flag-key', 'distinct_id_of_your_user', enabledVariant)
    }
  6. 6

    Include feature flag information in events

    Required

    If you want to use your feature flag to breakdown or filter events in your insights, you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.

    Note: This step is only required for events captured using our server-side SDKs or API.

    Set sendFeatureFlags to true in your capture call:

    Node.js

    PostHog AI

    client.capture({
        distinctId: 'distinct_id_of_your_user',
        event: 'event_name',
        sendFeatureFlags: true,
    })

    Include $feature property

    Include the $feature/feature_flag_name property in your event properties:

    Node.js

    PostHog AI

    client.capture({
        distinctId: 'distinct_id_of_your_user',
        event: 'event_name',
        properties: {
            '$feature/feature-flag-key': 'variant-key' // replace feature-flag-key with your flag key. Replace 'variant-key' with the key of your variant
        },
    })
  7. 7

    Override server properties

    Optional

    Sometimes, you may want to evaluate feature flags using properties that haven't been ingested yet, or were set incorrectly earlier. You can provide properties to evaluate the flag with:

    await client.getFeatureFlag(
        'flag-key',
        'distinct_id_of_the_user',
        {
            personProperties: {
                'property_name': 'value'
            },
            groups: {
                "your_group_type": "your_group_id",
                "another_group_type": "your_group_id",
            },
            groupProperties: {
                'your_group_type': {
                    'group_property_name': 'value'
                },
                'another_group_type': {
                    'group_property_name': 'value'
                },
            },
        }
    )
  8. 8

    Running experiments

    Optional

    Experiments run on top of our feature flags. Once you've implemented the flag in your code, you run an experiment by creating a new experiment in the PostHog dashboard.

  9. 9

    Next steps

    Recommended

    Now that you're evaluating flags, continue with the resources below to learn what else Feature Flags enables within the PostHog platform.

    ResourceDescription
    Creating a feature flagHow to create a feature flag in PostHog
    Adding feature flag codeHow to check flags in your code for all platforms
    Framework-specific guidesSetup guides for React Native, Next.js, Flutter, and other frameworks
    How to do a phased rolloutGradually roll out features to minimize risk
    More tutorialsOther real-world examples and use cases
Community questions

Ask a question

Was this page useful?

HelpfulCould be better

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs an MCP server

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
PostHog
Publisher
PostHog (Official)
Source
PostHog/skills · skills/posthog/feature-flags/skills/nodejs · commit a5d30e7
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
PostHog/skills

AutoGineer is not affiliated with or endorsed by PostHog.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download feature-flags-nodejs.zip