Creating the Project
Run the following commands to create a new directory and initialize it as a Node.js project:
mkdir effect-http-apicd effect-http-apipnpm initInstalling Dependencies
Run the following command to install the dependencies:
pnpm add effect@4.0.0-beta.46 @effect/platform-node@4.0.0-beta.46pnpm add -D typescript tsx @types/nodeWhat is @effect/platform-node and why do we need it?
To run an HTTP API, you need a server. Effect has an HTTP server module, but it only defines abstract interfaces for things like servers, requests, and responses. Since we are building a Node.js project, we need something that connects these abstract interfaces to the Node.js runtime. This is where @effect/platform-node comes in. It provides the Node.js-specific implementations of those interfaces, so that Effect’s HTTP server can actually listen on a port and handle requests using Node.js under the hood.
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-api", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "tsx watch server.ts" }, "keywords": [], "author": "", "license": "ISC", "type": "module", "packageManager": "pnpm@10.28.0", "dependencies": { "@effect/platform-node": "4.0.0-beta.46", "effect": "4.0.0-beta.46" }, "devDependencies": { "@types/node": "^25.5.1", "tsx": "^4.21.0", "typescript": "^6.0.2" }}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; you’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": "./ecom", "outDir": "./dist" }, "include": ["ecom/**/*.ts"]}Your project setup is now complete.