Core (Node.js) Integration

Learn how to integrate feature flags into your Node.js applications and services

Getting Started with Core SDK

The core package of MyFlags SDK, providing the fundamental functionality for feature flag management in any JavaScript environment.

Installation

npm install @myflags/core

Basic Setup

Initialize the SDK with your configuration:

import { MyFlagsSDK } from "@myflags/core";

// Initialize the SDK with your configuration
const sdk = new MyFlagsSDK({
  apiKey: "your-api-key",
  projectId: "your-project-id",
  environment: "production", // optional, defaults to 'production'
  refreshInterval: 600000, // optional, defaults to 10 minutes
});

Checking Feature Flags

Use the SDK to check feature flags:

// Get all feature flags
const flags = await sdk.getFlags();

// Check if a specific feature is enabled
const isEnabled = await sdk.getFlag("feature_key");

Real-time Updates

Subscribe to flag updates to get real-time notifications when flags change:

const sdk = new MyFlagsSDK({
  apiKey: "your-api-key",
  projectId: "your-project-id",
  refreshInterval: 5000, // Check for updates every 5 seconds
});

// Subscribe to flag updates
const unsubscribe = await sdk.subscribe((flags) => {
  console.log("Flags updated:", flags);
});

// Later, when you want to stop receiving updates
unsubscribe();

Features

Type Safety

Full TypeScript support with type-safe flag names and values.

Environment Support

Manage different flag states across development, staging, and production environments.

Performance

Optimized for performance with caching and efficient updates.

Real-time Updates

Subscribe to flag changes and get real-time updates.