The chapters in this course contain code snippets that are self-contained. I highly recommend you type them by hand and run them rather than passively reading through the content. This will help you understand and retain the concepts far better.
You can create a Node.js project by following the steps below.
Creating a Project
Create a new directory and initialize a Node.js project:
mkdir effect-scopecd effect-scopepnpm initInstalling Dependencies
Run the following command to install the required packages:
pnpm add effect@4.0.0-beta.42pnpm add -D typescript tsx @types/nodeConfiguring the Project
Add "type": "module" to your package.json to enable ES modules:
{ "name": "effect-scope", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "type": "module", "packageManager": "pnpm@10.28.0", "dependencies": { "effect": "4.0.0-beta.42" }, "devDependencies": { "@types/node": "^25.5.0", "tsx": "^4.21.0", "typescript": "^6.0.2" }}Create a tsconfig.json in the project root:
{ "compilerOptions": { "target": "ES2022", "module": "nodenext", "moduleResolution": "nodenext", "strict": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "outDir": "./dist" }, "include": ["*.ts"]}Creating a TypeScript File
Create a file named resource-leak-demo.ts in the project root. This is the file where we will write all of our code.
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 run the file, use:
npx tsx resource-leak-demo.tsNote that tsx does not perform type checking. To catch type errors, run npx tsc --noEmit separately.