@effect/platform
is a library for building platform-independent abstractions in environments such as Node.js, Bun, and browsers.
With @effect/platform
, you can integrate abstract services like Terminal
, FileSystem
or Path
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
@effect/platform-bun
for Bun
@effect/platform-browser
for browsers
Experimental Features Notice
Some modules in @effect/platform
are still in development or marked as
experimental. These features are subject to change. For the most
up-to-date documentation and details, please refer to the official
README
of the package.
To install the beta version:
npm install @effect/platform
pnpm add @effect/platform
yarn add @effect/platform
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)
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" )
Running the Program in Node.js
First, install the Node.js-specific package:
npm install @effect/platform-node
pnpm add @effect/platform-node
yarn add @effect/platform-node
Update the program to load the Node.js-specific context:
Example (Providing Node.js Context)
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" )
NodeRuntime . runMain ( program . pipe ( Effect . provide ( NodeContext . layer )))
Finally, run the program in Node.js using tsx
:
Running the Program in Bun
To run the same program in Bun, first install the Bun-specific package:
bun add @effect/platform-bun
Update the program to use the Bun-specific context:
Example (Providing Bun Context)
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" )
BunRuntime . runMain ( program . pipe ( Effect . provide ( BunContext . layer )))
Run the program in Bun: