DEV Community

Cover image for Directus.js (JavaScript SDK) – The official client for Directus APIs
Ahmed Niazy
Ahmed Niazy

Posted on

Directus.js (JavaScript SDK) – The official client for Directus APIs

Image description

If you're working with Directus, the open-source headless CMS and data platform, then Directus.js is your new best friend.

Directus.js is the official JavaScript SDK for interacting with Directus APIs. It offers a type-safe, modular, and fully composable interface for:

  • Authenticating users
  • Fetching data via REST or GraphQL
  • Subscribing to real-time updates
  • Managing files and content

✅ Why use Directus.js?

  • Written in TypeScript – get autocompletion and strong types
  • Supports REST and GraphQL out of the box
  • Built with a composable architecture – import only what you need
  • Works in both browser and Node.js environments
  • Makes authentication and token management a breeze

🧪 Example

import { createDirectus, rest, readItems } from '@directus/sdk';

const directus = createDirectus('https://your-directus-url.com').with(rest());

const articles = await directus.request(readItems('articles'));
console.log(articles);
Enter fullscreen mode Exit fullscreen mode

🛠️ Installation

npm install @directus/sdk
Enter fullscreen mode Exit fullscreen mode

Or use Yarn:

yarn add @directus/sdk
Enter fullscreen mode Exit fullscreen mode

🔗 Want to dive deeper?
Check out the full documentation at https://docs.directus.io/reference/sdk/


Learn More

Top comments (0)