Quickstart
In this tutorial, we will guide you through the process of setting up a new Effect project from scratch using plain TypeScript 5.0 or newer.
Follow these steps to create a new Effect project for Node.js:
-
As a first step, create a project directory and navigate into it:
Terminalbashmkdir hello-effectcd hello-effectTerminalbashmkdir hello-effectcd hello-effect -
Next, initialize a TypeScript project using npm (make sure you have TypeScript 5.0 or newer):
Terminalbashnpm init -ynpm install typescript --save-devTerminalbashnpm init -ynpm install typescript --save-devThis creates a
package.json
file with an initial setup for your TypeScript project. -
Now, initialize TypeScript:
Terminalbashnpx tsc --initTerminalbashnpx tsc --initWhen running this command, it will generate a
tsconfig.json
file that contains configuration options for TypeScript. One of the most important options to consider is thestrict
flag.Make sure to open the
tsconfig.json
file and verify that the value of thestrict
option is set totrue
.tsconfig.jsonjson{"compilerOptions": {"strict": true}}tsconfig.jsonjson{"compilerOptions": {"strict": true}} -
Then, install the necessary package as dependency:
Terminalbashnpm install effectTerminalbashnpm install effectThis package will provide the foundational functionality for your Effect project.
Let's write and run a simple program to ensure that everything is set up correctly.
In your terminal, execute the following commands:
bash
mkdir srctouch src/index.ts
bash
mkdir srctouch src/index.ts
Open the index.ts
file and add the following code:
ts
import { Effect, Console } from "effect"const program = Console.log("Hello, World!")Effect.runSync(program)
ts
import { Effect, Console } from "effect"const program = Console.log("Hello, World!")Effect.runSync(program)
Run the index.ts
file. If you have ts-node
installed, run the following command in the terminal:
bash
ts-node src/index.ts
bash
ts-node src/index.ts
You should see the message "Hello, World!"
printed. This confirms that the program is working correctly.