Creating the Project
Run the following commands to create a new directory and initialize it as a Node.js project:
mkdir effect-http-servercd effect-http-serverpnpm initInstalling Dependencies
Run the following command to install the dependencies:
pnpm add effect@4.0.0-beta.66 @effect/platform-node@4.0.0-beta.66pnpm add -D typescript tsx @types/nodeWhat is @effect/platform-node and why do we need it?
Effect ships an HTTP module (effect/unstable/http) that defines platform-agnostic interfaces for
servers, requests, responses, and routing, but it doesn’t include any code that actually binds to
a network port. Since we’re building on Node.js, we need something that connects those interfaces
to the Node.js runtime. That’s what @effect/platform-node provides. Its NodeHttpServer plugs
Node’s built-in node:http module into Effect’s HttpServer, so the server can listen on a port
and handle real requests.
Configuring the Project
Add "type": "module" to your package.json and replace the test script with a dev script as
shown below:
{ "name": "effect-http-server", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "tsx watch server.ts" }, "keywords": [], "author": "", "license": "ISC", "type": "module", "packageManager": "pnpm@10.33.1", "dependencies": { "@effect/platform-node": "4.0.0-beta.66", "effect": "4.0.0-beta.66" }, "devDependencies": { "@types/node": "^25.8.0", "tsx": "^4.22.0", "typescript": "^6.0.3" }}To start the dev server, you’ll run pnpm dev, which will run tsx watch server.ts under the
hood.
tsx is a TypeScript execution environment for Node.js. Node.js (v22.18.0
and later) can run TypeScript files natively. However, tsx offers additional features like watch
mode, which makes it a better fit for development. Watch mode automatically re-runs your script
whenever any of its imported files are changed. So every time you save a change, tsx will re-run
server.ts for you.
Note that the server.ts file doesn’t exist yet; we’ll create it in a later chapter.
Configuring TypeScript
Create a tsconfig.json file in the project root:
{ "compilerOptions": { "target": "ES2022", "module": "nodenext", "moduleResolution": "nodenext", "strict": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "rootDir": ".", "outDir": "./dist" }, "include": ["ecom/**/*.ts"]}Your project setup is now complete.