Project SetUp

Avatar of Hemanta SundarayHemanta Sundaray

Creating the Project

Run the following commands to create a new directory and initialize it as a Node.js project:

Terminal
mkdir effect-http-api
cd effect-http-api
pnpm init

Installing Dependencies

Run the following command to install the dependencies:

Terminal
pnpm add effect@4.0.0-beta.46 @effect/platform-node@4.0.0-beta.46
pnpm add -D typescript tsx @types/node

What 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:

package.json
{
"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:

tsconfig.json
{
"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.

Sign in to save progress

Stay in the loop

Get notified when new Effect HTTP API related content is published.