[API reference](https://evolu.dev/docs/api-reference) › [@evolu/nodejs](https://evolu.dev/docs/api-reference/nodejs) › runMain

## Call Signature

```ts
function runMain<T>(main: Task<T>, options?: RunMainOptions): Promise<void>;
```

Defined in: [packages/nodejs/src/Task.ts:106](https://github.com/evoluhq/evolu/blob/59dabb7c56c68040b30d3919013adeb2b40bad10/packages/nodejs/src/Task.ts#L106)

Runs the main Task as the Node.js program lifecycle.

Creates one root [Run](https://evolu.dev/docs/api-reference/common/Task/interfaces/Run) and aborts it on:

- `SIGINT`: Ctrl-C on all platforms.
- `SIGTERM`: OS, service, Docker, or Kubernetes termination on Unix.
- `SIGBREAK`: Ctrl-Break on Windows.

The first signal logs shutdown progress, aborts the root Run, and waits for
the main Task and structured cleanup to finish. A subsequent signal exits
immediately with its conventional signal status, abandoning cleanup. A signal
received during final cleanup still applies signal shutdown behavior.

A main Task returning [Resource](https://evolu.dev/docs/api-reference/common/Resource/type-aliases/Resource) keeps the program running until a
termination signal and is disposed during shutdown. A main Task returning
`void` completes the program immediately. A Resource result transfers
ownership of a live resource that must remain valid after its creating Task
settles.

Service mode treats graceful signal shutdown as successful. Command mode
preserves conventional signal exit statuses. Every defect reported through
`reportDefect`, including an observer defect that does not abort the Run,
sets `process.exitCode` to 1. The default reporter logs to the configured
Evolu console.

Escaped uncaught exceptions and unhandled rejections remain under Node.js
native reporting and termination.

### Service Example

```ts
const deps = { ...createRelayDeps(), console: createConsole() };

await runMain(deps)(createRelay({ port: 4000 }));
```

A Task returning `void` can keep a service alive explicitly when no Resource
owns its lifetime:

```ts
await runMain(deps)(async (run) => {
  void run(processMessages);
  return await run(waitForAbort);
});
```

### Command Example

```ts
await runMain(command, { mode: "command" });
```

## Call Signature

```ts
function runMain<D>(
  deps: RunCustomDeps<D>,
  options?: RunMainOptions,
): <T>(main: Task<T, never, D>) => Promise<void>;
```

Defined in: [packages/nodejs/src/Task.ts:111](https://github.com/evoluhq/evolu/blob/59dabb7c56c68040b30d3919013adeb2b40bad10/packages/nodejs/src/Task.ts#L111)

With custom dependencies.