Skip to main content

Overview

The Directus JavaScript SDK provides a TypeScript-first, modular, and lightweight client for interacting with the Directus API. It has zero external dependencies and works in both browser and Node.js environments.

Features

  • TypeScript first: Robust and type-safe development experience
  • Modular architecture: Mix and match features to compose a custom client
  • Lightweight and dependency-free: No external libraries required
  • Works everywhere: Browser, Node.js, and edge runtimes

Installation

Install the SDK using your preferred package manager:

Requirements

  • Node.js 22 or higher (for server-side usage)
  • Modern browser with ES modules support (for client-side usage)

Basic Setup

The SDK uses a composable architecture. Start by creating a base client, then add features as needed:

Available Composables

The SDK provides several composable features that can be added to your client:
  • rest() - REST API request functions (adds .request() method)
  • graphql() - GraphQL query functions (adds .query() method)
  • authentication() - Full authentication with login/logout/refresh
  • staticToken() - Static token authentication
  • realtime() - WebSocket connectivity for real-time updates

TypeScript Schema Definition

For full type safety, define your schema interface:

Custom Globals

You can provide custom implementations for fetch, WebSocket, URL, and logger:

Next Steps

Authentication

Learn how to authenticate with the SDK

Items Operations

Work with collection items (CRUD operations)

Real-time

Subscribe to real-time updates via WebSocket

Files

Upload and manage files