Project Setup

Avatar of Hemanta SundarayHemanta Sundaray

Let’s set up our project with the required dependencies.

Installing Dependencies

Create a new directory and initialize a project:

Terminal
mkdir effect-http-client
cd effect-http-client
npm init -y

Install the required packages:

Terminal
npm install effect@4.0.0-beta.6 @effect/platform-node@4.0.0-beta.6
npm install -D typescript tsx @types/node

@effect/platform-node provides Node.js-specific implementations for Effect’s platform services. Effect defines abstract services like FileSystem and Path that your code uses, and @effect/platform-node supplies the concrete Node.js implementations that make them work. We’ll need this in a later chapter when we learn to upload files from the local filesystem.

In Effect v4, many packages that were previously separate have been consolidated into the core effect package. HttpClient is one of them. It now lives in effect as an unstable module. This is why our install command only has two packages: effect for the core library (which includes HttpClient), and @effect/platform-node for Node.js-specific services like filesystem access.

Configuring the Project

Add "type": "module" to your package.json to enable ES modules:

package.json
{
"name": "effect-http-client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"@effect/platform-node": "4.0.0-beta.6",
"effect": "4.0.0-beta.6"
},
"devDependencies": {
"@types/node": "^25.2.3",
"tsx": "^4.21.0",
"typescript": "^5.9.3"
}
}

Create a tsconfig.json in the project root:

tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist"
},
"include": ["*.ts"]
}

Running TypeScript Files

We use tsx to run TypeScript files directly without a separate compilation step. Every code snippet in this course is complete and runnable. To try any example, copy the code into a .ts file (e.g., http.ts) and run it with:

Terminal
npx tsx http.ts

Note that tsx does not perform type checking. To catch type errors, run npx tsc --noEmit separately.

Note

When you copy the code snippets from this course into your editor, you’ll see TypeScript errors when accessing properties on data returned from response.json (for example, user.firstName or product.title). This is because response.json returns unknown, and we access properties without validating the response shape first.

This is intentional. Each code snippet is focused on the specific API being discussed, and adding schema validation to every example would distract from the topic at hand. In a real application, you’d use HttpClientResponse.schemaBodyJson() to validate and type the response, which is covered in its own chapter.

Sign in to save progress

Stay in the loop

Get notified when new chapters are added and when this course is complete.