Skip to content
Agents: this page is Markdown at /effect-handbook/foundations/getting-started.md · llms.txt · reading guide View raw

Getting Started ​

Everything else in this handbook assumes a project where Effect is installed, TypeScript is strict, and one entrypoint runs an Effect. This page gets you there and names the traps on the way: mismatched package versions, compiler settings that silently weaken the types, and packages that do not exist for Effect 4.

Official guides: Installation (asks for Node.js 22.18+; the release-matched README states Node.js 22.19+ as the general minimum), Importing Effect, The Effect Type, Creating Effects, Running Effects (it names the runFork result RuntimeFiber; the type is Fiber), Using Generators, Building Pipelines (it calls Option and Result yieldable inside Effect.gen; they are not — use Effect.fromOption and Effect.fromResult), Devtools. These track Effect's main branch rather than this edition's audited release, so where they differ, this page and the tagged source win.

Install Effect 4 ​

Effect 4 is the latest release on npm: a plain pnpm add effect installs it. Pin the exact version anyway, so that an upgrade is a deliberate, audited change rather than a side effect of a fresh install.

sh
pnpm add effect@4.1.4 @effect/platform-node@4.1.4
pnpm add -D typescript@7 @types/node

Keep application effect and @effect/* integration packages on one release. These packages are released together. Pin matching versions for the platform, SQL, provider, UI, and testing adapters: each is built and tested against that release, and subsystem families under effect/<area> may change between minor releases. Developer tools such as @effect/tsgo have their own version line. Check for a single copy with pnpm why effect (or npm ls effect) after every install; the Effect language service reports a second copy as duplicatePackage.

Install when you needPackage
The core, plus every effect/<area> family (HTTP, RPC, SQL client, CLI, AI, JOSE, cluster, workflow, …)effect — no runtime dependencies
A process entrypoint, file system, HTTP server or client for a host@effect/platform-node, @effect/platform-bun, @effect/platform-deno, @effect/platform-browser
A SQL driver@effect/sql-pg, @effect/sql-pglite, @effect/sql-sqlite-node, and the other @effect/sql-* packages
A language-model provider@effect/ai-openai, @effect/ai-anthropic, @effect/ai-openrouter, @effect/ai-openai-compat
OpenTelemetry SDK export, UI bindings, test helpers@effect/opentelemetry, @effect/atom-react (also -solid, -vue), @effect/vitest

Do not install @effect/platform, @effect/cli, @effect/rpc, @effect/sql, @effect/cluster, @effect/workflow, @effect/ai, or @effect/experimental: they have no Effect 4 release, and their modules ship inside effect under effect/<area> paths such as effect/http, effect/rpc, and effect/sql.

Runtime and compiler requirements ​

The library's floor and this handbook's validation target are different things. The first column is what the audited release asks of you; the second is what every example here is compiled and run with.

Required by Effect (release-matched README and package metadata)Used to validate this handbook
TypeScript5.9 or newer; TypeScript 7 recommended7.0.2
Node.js22.19 or newer (the README's general minimum; @effect/platform-node, @effect/platform-node-shared, and @effect/opentelemetry declare engines.node >=22.19.0); on Deno, @effect/platform-deno declares engines.deno >=2.9.326, which runs .ts entrypoints directly
Test runner@effect/vitest and @effect/doctest require Vitest 5; @effect/atom-react requires React 19Vitest 5.1.1
Type checkingstrict: truestrict plus the flags below
Module formatESM only: the packages are "type": "module" with no CommonJS buildmodule: NodeNext

Set "type": "module" in your own package.json, then start from this tsconfig.json:

json
{
  "compilerOptions": {
    "target": "ES2025",
    "lib": ["ES2025"],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "moduleDetection": "force",
    "strict": true,
    "exactOptionalPropertyTypes": true,
    "noUncheckedIndexedAccess": true,
    "verbatimModuleSyntax": true,
    "erasableSyntaxOnly": true,
    "rewriteRelativeImportExtensions": true,
    "skipLibCheck": true,
    "types": ["node"],
    "plugins": [{ "name": "@effect/language-service" }]
  }
}
SettingStatusWhy it matters for Effect code
strictrequiredWithout it, E and R inference degrades and null flows through unchecked.
target / lib: ES2025handbook choice; set both to your oldest runtimeES2025 is the newest target TypeScript 7 accepts. It assumes a current runtime — Node.js 24+ or a current evergreen browser — for library APIs such as Promise.try and Iterator helpers. Effect itself needs nothing newer than ES2022, so lower both settings together when you support older hosts; add "DOM" to lib for browser code.
exactOptionalPropertyTypesrecommended; on in the Effect repository and in this handbookKeeps "key absent" and "key present with undefined" distinct, which is the difference between Schema.optionalKey and Schema.optional.
module / moduleResolution: NodeNext (or Bundler behind a bundler)required in practiceBoth honor the package exports map; subpaths such as effect/http and effect/testing do not resolve under legacy node10 resolution.
verbatimModuleSyntax, erasableSyntaxOnly, rewriteRelativeImportExtensionsrecommended; on in the Effect repositorySource stays runnable by a type-stripping runtime: type-only imports are written import type, and enums, namespaces, and constructor parameter properties are rejected.
noUncheckedIndexedAccesshandbook choiceArray and record lookups produce T | undefined, which pairs naturally with Option.fromNullishOr.
plugins: @effect/language-servicerecommendedEnables Effect diagnostics; see Effect diagnostics in the editor and in CI.

A first complete program ​

One file, one runtime call. NodeRuntime.runMain is the process edge: it forks the program as the root fiber, interrupts it on SIGINT or SIGTERM so finalizers run, reports an unhandled failure through the logger, and sets the exit code (0 on success, 130 when the program was only interrupted, non-zero on failure). The runtime itself keeps the process alive while fibers are pending, so runMain is about signals, exit codes, and error reporting rather than liveness.

Self-contained source · Type-checked

ts
import { NodeRuntime } from "@effect/platform-node"
import { Effect, Schema } from "effect"

class RaiseOutOfBand extends Schema.TaggedError<RaiseOutOfBand>()("RaiseOutOfBand", {
  percent: Schema.Finite,
  maximum: Schema.Finite
}) {}

// An Effect-returning function: traced, and typed as
// (salary, percent) => Effect<number, RaiseOutOfBand>
const proposeRaise = Effect.fn("proposeRaise")(function*(salary: number, percent: number) {
  if (percent > 0.15) {
    return yield* new RaiseOutOfBand({ percent, maximum: 0.15 })
  }
  yield* Effect.logInfo(`raise of ${percent * 100}% accepted`)
  return Math.round(salary * (1 + percent))
})

// Inline composition. Nothing has run yet: `program` is a description.
const program = Effect.gen(function*() {
  const next = yield* proposeRaise(120_000, 0.04)
  yield* Effect.logInfo(`new salary: ${next}`)
})

NodeRuntime.runMain(program)
text
$ node src/main.ts
[20:40:57.787] INFO (#2): raise of 4% accepted
[20:40:57.788] INFO (#2): new salary: 124800

Change 0.04 to 0.4 and the process logs ERROR (#2): RaiseOutOfBand with a stack that points at proposeRaise, then exits with code 1.

Four reading rules carry into every other page:

  • Effect<A, E, R> is a description: it succeeds with A, fails with a typed E, and needs services R. Building one performs no work, so Effect.succeed(Date.now()) reads the clock while the program is being built; write Effect.sync(() => Date.now()).
  • yield* sequences; return yield* fails. Inside Effect.gen and Effect.fn, yield* runs an Effect and gives you its value. Yielding a tagged error fails the Effect, and the return tells TypeScript the code after it is unreachable.
  • E = never means "no modeled failure is left", not "cannot go wrong". Defects and interruption exist regardless of the error type.
  • Run at an edge you own. Reusable code returns Effects; only an entrypoint, a host adapter, or a test calls a runner.
EdgeRunnerOn failure
Process entrypointNodeRuntime.runMain (BunRuntime, DenoRuntime in their packages)logs, sets the exit code
JavaScript caller that wants a PromiseEffect.runPromiserejects with the failure value or defect; only an Exit runner tells failure, defect, and interruption apart
Caller that must branch on the outcomeEffect.runPromiseExit, Effect.runSyncExitresolves with an Exit
Provably synchronous effectEffect.runSyncthrows, including when the effect turns out to be asynchronous
Caller that keeps and owns the fiberEffect.runForkreturns a Fiber; someone must join, observe, or interrupt it
A host that calls in repeatedly (web framework, UI)one ManagedRuntimeper runner, as above; dispose it on shutdown

Details: Effect, Runtime, and ManagedRuntime. BrowserRuntime.runMain is the browser equivalent; see Platform & Runtime Hosts.

Import forms ​

Self-contained source · Type-checked

ts
// Barrel: every root module as a namespace. The handbook uses this form.
import { Effect, Layer, Schema } from "effect"

// Subpath: one module per import. Same module instance as the barrel export.
import * as Option from "effect/Option"

// Area families have their own barrels and per-module subpaths.
import { HttpClient } from "effect/http"
import * as HttpClientRequest from "effect/http/HttpClientRequest"

// Test services live under their own entry point.
import { TestClock } from "effect/testing"
  • The module label on every handbook section — `effect/Queue` — stable — is the subpath. The example beneath it imports the same module from the barrel; the two are interchangeable.
  • Tree-shaking is a bundler property, enabled by the package. effect declares its side-effect-free modules and exposes its API as module functions rather than methods, so a bundler can drop what a program never references. When a bundler or test runner handles the barrel poorly, switch that project to subpath imports; no call site changes.
  • effect/internal/* and */index subpaths are blocked by the exports map. If an import needs them, the API is not public.
  • Functions are dual. Effect.map(effect, f) and effect.pipe(Effect.map(f)) are the same operation; use the first for one step and .pipe for several.

Stable and unstable modules ​

Stability is a per-API contract declared with a JSDoc tag, not an import path; since 4.0.2 every module and directly importable export is tagged explicitly. The handbook summarizes it as a badge on every module section.

BadgePromiseWhat carries it
stable (@stability stable)semantic versioning: breaking changes only in a major releasemost of the root barrel — Effect, Layer, Schema, Stream, Config, the data structures, most Tx* transactional modules — plus TestClock from effect/testing and the text codecs under effect/encoding (Base64, Base64Url, Hex, EncodingError)
unstable (@stability unstable)may break in a minor releasethe subsystem families effect/ai, cli, cluster, devtools, eventlog, http, http-api, jose, net, observability, persistence, process, reactivity, rpc, schema, socket, sql, workers, workflow; root-barrel modules such as Arbitrary, FileSystem, Path, ExecutionPlan, LayerMap, Graph, and ByteSize (each module section shows its badge); TestConsole and TestSchema; the remaining effect/encoding codecs; some advanced Schema APIs; and every API that exposes a third-party dependency (driver options in @effect/sql-*, provider clients in @effect/ai-*, @effect/opentelemetry)
experimental (@stability experimental)may break in a patch releaseeffect/graphql; Host, Dns, and AddressResolver in effect/net; the related host and DNS schemas in Schema

"Unstable" describes the API contract, not the quality: HTTP, SQL, and RPC are what production Effect applications are built on. It does change how you depend on them. Pin exact versions, read the release notes before every upgrade, and keep leaf area imports behind a small service you own so a rename touches one file. The maintainers' stated plan is to promote these families to stable as production feedback settles them.

Effect diagnostics in the editor and in CI ​

The Effect language service ships as @effect/tsgo, built on the native TypeScript compiler, and needs typescript 7 installed beside it. It adds Effect-aware diagnostics and quick fixes: an Effect that was never yielded or assigned, a bare yield without *, implementation services leaking through a service method, a second copy of an Effect package, and APIs that do not exist in the installed version. npx @effect/tsgo setup adds the dependency and the @effect/language-service entry under compilerOptions.plugins; effect-tsgo patch (run it from a prepare script, as the Effect repository does) patches the local TypeScript install so tsc emits the same diagnostics; and npx @effect/tsgo diagnostics --project tsconfig.json --strict is a standalone CI check in which warnings fail the build. This handbook compiles every example under exactly that pair: strict tsc and strict Effect diagnostics, with one rule turned off: unstableApiUsage warns on every API tagged @stability unstable, including effect/http, effect/sql, effect/rpc, effect/ai, and the other unstable area families. A project that uses those modules sets "diagnosticSeverity": { "unstableApiUsage": "off" } in the plugin options (or downgrades it to a suggestion) rather than suppressing it line by line; a project that wants to be told when it strays outside the semver-covered surface leaves it on.

The official guidance for working with coding agents makes the same point from the other side: the tighter the feedback loop, the better the generated code, so install the language service first, and keep the installed effect source (and its bundled AGENTS.md and ai-docs/) within the agent's reach rather than relying on remembered API shapes. Testing & Dev Tooling covers the tooling in depth.

First-session route: a small approval worker ​

After the first program, follow these five stops in order. Grow one small worker that processes raise proposals through a replaceable approval service; use an in-memory fake and a counted resource rather than a real payroll connection. The recipes are patterns to adapt, not successive files to paste together. These are self-check exercises, not automatically executed or graded lessons.

  1. Model errors. Read Designing the error model, then Effect error handling.

    Exercise: Give an over-limit proposal a tagged failure and recover from that tag at the worker boundary; keep an unexpected bug distinct.

    Done when: An accepted proposal succeeds, an over-limit proposal reaches its named handler, and a defect does not reach that handler.

  2. Define and test a service. Read Designing a service contract, then the service recipe's Complete file and Variations.

    Exercise: Put approval behind a service whose method retains step 1's expected error. Substitute a recording fake and assert the submitted proposal and result.

    Done when: The assertion depends on a call recorded only by the fake; the same worker runs unchanged with either implementation.

  3. Own resources. Read Scope, then the bounded worker's Complete file.

    Exercise: Adapt its counted per-job acquisition/release around approval. Try success, a typed failure, and interruption while a job is active.

    Done when: Each acquired handle is released exactly once after its job ends, including the failed and interrupted cases.

  4. Compose Layers. Read Resourceful services, then Reading and composing the graph.

    Exercise: Give the approval service a counted app-lifetime client, distinct from the per-job handle. Wire client → service → worker, and provide the graph once at the edge.

    Done when: The runnable worker has no remaining service requirements; two jobs share one client acquisition, and that client closes once when the owning scope ends.

  5. Run and shut down. Read the graceful entrypoint's Complete file and Why these primitives?.

    Exercise: Host the worker as scoped background work in an application Layer, launch it with the platform runner, and send SIGINT or SIGTERM during a job.

    Done when: The active job releases its handle, the app-lifetime client closes, and the process exits without leaving the worker running.

Keep the first pass small: no network, database, or readiness endpoint. Once these checks are clear, add a bounded retry policy using Typed Retry with TestClock: Assert the shape of the policy, or extend shutdown with Adding readiness and a bounded drain.

Where next ​

You want toGo to
Understand Effect, fibers, scopes, and runnersCore Runtime & Execution
Model failures, absence, and recoverable resultsErrors, Option & Result
Inject dependencies and own resource lifetimesServices, Context & Layers, then Recipe: A Service with Live and Test Layers
Read environment variables and secretsConfiguration & Secrets
Validate and transform data at a boundarySchema
Pick between similar primitivesChoosing Effect Primitives
See the whole application shapeAnatomy of a Real Effect Application
Bring Effect into a Promise-based codebaseAdopting Effect in an Existing TypeScript Codebase
Write a production entrypointRecipe: A Graceful Node Entrypoint
Test with virtual time and replaceable servicesTesting & Dev Tooling and Testing an Effect Application
Diagnose a confusing type error or a hangTroubleshooting & Anti-Patterns
Review a change before it shipsReview Checklists

Edition 4.1 · audited 2026-11-19 against Effect 4.1.4.