# main

```ts
async function main(body: (args: string[]) => Operation<void>): Promise<void>
```

Top-level entry point to programs written in Effection. That means that your
program should only call `main` once, and everything the program does is
handled from within `main` including an orderly shutdown. Unlike `run`, `main`
automatically prints errors that occurred to the console.

Use the [exit](https://frontside.com/effection/api/v4-next/exit.md) operation form within to halt program execution
immediately and initiate shutdown.

The behavior of `main` is slightly different depending on the environment it
is running in.

### Deno, Node

When running within Deno or Node, any error which reaches `main` causes the
entire process to exit with an exit code of `1`.

Additionally, handlers for `SIGINT` are attached to the
process, so that sending an exit signal to it causes the main task
to become halted. This means that hitting CTRL-C on an Effection program
using `main` will cause an orderly shutdown and run all cleanup code.

> Warning! do not call `Deno.exit()` on Deno or `process.exit()` on Node
> directly, as this will not gracefully shutdown. Instead, use the
> [exit](https://frontside.com/effection/api/v4-next/exit.md) operation.

### Browser

When running in a browser, The `main` operation gets shut down on the
`unload` event.

### Parameters


**body**: (**args**: string&lbrack;&rbrack;) => [Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;void&gt;


an operation to run as the body of the program
### Return Type


Promise&lt;void&gt;


a promise that resolves right after the program exits

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/main.ts#L63)
