Skip to content

Command Line Application with Effect

In this tutorial, you will learn how to create a command-line application using typescript-effect template in the repository. It is an opinionated template with convenient tooling.

The initialized project will be a complete development environment with the following dependencies:

This template provides:

  • Effect
  • ESLint (based on antfu's config)
  • Build tool: tsup for bundling
  • Development tools: tsx for hot-reloading, lefthook for git hooks
  • Package manager: pnpm via corepack. You can easily switch to Bun

With some tweaks, you can also create a server application.

  1. Create a new directory for your project:

    Terminal window
    nix flake new -t github:akirak/flake-templates#typescript-effect my-app
  2. Enter the directory:

    Terminal window
    cd my-app
  3. Add .envrc:

    Terminal window
    use flake
  4. Allow direnv:

    Terminal window
    direnv allow
  5. Delete the license header comment from package.json:

    // Delete this comment for this package.json to work
    // SPDX-License-Identifier: Unlicense
    {
    "name": "my-effect-app",
    ...
    }
  6. Update the dependencies:

    Terminal window
    pnpm update
  7. Tweak the generated configuration files to suit your preferences.

The template includes a minimal example CLI application in src/main.ts.

Key configuration files:

  • package.json: Pre-configured scripts for development, building, linting, and type checking
  • tsconfig.json: TypeScript configuration with Effect Language Service plugin
  • eslint.config.js: ESLint setup using @antfu/eslint-config with Effect-specific overrides
  • lefthook.yml: Git hooks for pre-commit linting and pre-push type checking

The template includes a simple "hello" command that you can run:

Terminal window
# Run in development mode with hot-reloading
pnpm dev hello --name World
# Or run with tsx directly
tsx src/main.ts hello --name World
Terminal window
# Type checking
pnpm typecheck
# Linting
pnpm lint
# Fix linting issues
pnpm lint-fix
# Run tests (when added)
pnpm test
# Build the application
pnpm build
  1. Playwright support: The flake includes optional Playwright browser testing support. Enable it by setting enablePlaywright = true in flake.nix. Also uncomment the relevant section in the generated GitHub workflow.

  2. Frontend development: The ESLint config includes commented-out sections for React and TanStack Router support. Uncomment these if building a frontend application.

  • The template disables several ESLint rules that conflict with Effect's coding style (like array-callback-return and no-lone-blocks)
  • The TypeScript configuration includes the Effect Language Service plugin for better IDE support
  • Explore the Effect documentation to learn more about the library
  • Check out @effect/cli documentation for building complex CLI applications
  • Add testing with vitest (already configured in package.json but the dependencies hasn't been added)