Skip to content
Docs menu / Introduction

Introduction to Effect Platform

@effect/platform is a library for building platform-independent abstractions in environments such as Node.js, Deno, Bun, and browsers.

With @effect/platform, you can integrate abstract services like FileSystem or Terminal into your program. When assembling your final application, you can provide specific layers for the target platform using the corresponding packages:

  • @effect/platform-node for Node.js or Deno
  • @effect/platform-bun for Bun
  • @effect/platform-browser for browsers

Stable Modules

The following modules are stable and their documentation is available on this website:

Module Description Status
Command Provides a way to interact with the command line. Stable
FileSystem A module for file system operations. Stable
KeyValueStore Manages key-value pairs for data storage. Stable
Path Utilities for working with file paths. Stable
PlatformLogger Log messages to a file using the FileSystem APIs. Stable
Runtime Run your program with built-in error handling and logging. Stable
Terminal Tools for terminal interaction. Stable

Unstable Modules

Some modules in @effect/platform are still in development or marked as experimental. These features are subject to change.

Module Description Status
Http API Provide a declarative way to define HTTP APIs. Unstable
Http Client A client for making HTTP requests. Unstable
Http Server A server for handling HTTP requests. Unstable
Socket A module for socket-based communication. Unstable
Worker A module for running tasks in separate workers. Unstable

For the most up-to-date documentation and details, please refer to the official README of the package.

Installation

To install the beta version:

Terminal window
npm install @effect/platform
Terminal window
pnpm add @effect/platform
Terminal window
yarn add @effect/platform
Terminal window
bun add @effect/platform
Terminal window
deno add npm:@effect/platform

Getting Started with Cross-Platform Programming

Here’s a basic example using the Path module to create a file path, which can run across different environments:

Example (Cross-Platform Path Handling)

index.ts
import { Path } from "@effect/platform"
import { Effect } from "effect"
const program = Effect.gen(function* () {
// Access the Path service
const path = yield* Path.Path
// Join parts of a path to create a complete file path
const mypath = path.join("tmp", "file.txt")
console.log(mypath)
})

Running the Program in Node.js or Deno

First, install the Node.js-specific package:

Terminal window
npm install @effect/platform-node
Terminal window
pnpm add @effect/platform-node
Terminal window
yarn add @effect/platform-node
Terminal window
deno add npm:@effect/platform-node

Update the program to load the Node.js-specific context:

Example (Providing Node.js Context)

index.ts
import { Path } from "@effect/platform"
import { Effect } from "effect"
import { NodeContext, NodeRuntime } from "@effect/platform-node"
const program = Effect.gen(function* () {
// Access the Path service
const path = yield* Path.Path
// Join parts of a path to create a complete file path
const mypath = path.join("tmp", "file.txt")
console.log(mypath)
})
NodeRuntime.runMain(program.pipe(Effect.provide(NodeContext.layer)))

Finally, run the program in Node.js using tsx, or directly in Deno:

tmp/file.txt
npx tsx index.ts
tmp/file.txt
pnpm dlx tsx index.ts
tmp/file.txt
yarn dlx tsx index.ts
tmp/file.txt
deno run index.ts
# or
deno run -RE index.ts
# Output: tmp/file.txt
# (granting required Read and Environment permissions without being prompted)

Running the Program in Bun

To run the same program in Bun, first install the Bun-specific package:

Terminal window
bun add @effect/platform-bun

Update the program to use the Bun-specific context:

Example (Providing Bun Context)

index.ts
import { Path } from "@effect/platform"
import { Effect } from "effect"
import { BunContext, BunRuntime } from "@effect/platform-bun"
const program = Effect.gen(function* () {
// Access the Path service
const path = yield* Path.Path
// Join parts of a path to create a complete file path
const mypath = path.join("tmp", "file.txt")
console.log(mypath)
})
BunRuntime.runMain(program.pipe(Effect.provide(BunContext.layer)))

Run the program in Bun:

Terminal window
bun index.ts
tmp/file.txt