Copy as Markdown[View as Markdown](/docs/sdk/functions/writeChannel.md)

***

# Function: writeChannel()

> **writeChannel**(`directory`): (`channel`, `options`) => `Promise`<`void`>

Defined in: channels.ts:116

Write a channel to EventCatalog.

You can optionally override the path of the channel.

## Parameters[​](#parameters "Direct link to Parameters")

| Parameter   | Type     |
| ----------- | -------- |
| `directory` | `string` |

## Returns[​](#returns "Direct link to Returns")

`Function`

### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter                         | Type                                                                                                           |
| --------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| `channel`                         | `Channel`                                                                                                      |
| `options`                         | { `format`: `"md"` \| `"mdx"`; `override`: `boolean`; `path`: `string`; `versionExistingContent`: `boolean`; } |
| `options.format`?                 | `"md"` \| `"mdx"`                                                                                              |
| `options.override`?               | `boolean`                                                                                                      |
| `options.path`?                   | `string`                                                                                                       |
| `options.versionExistingContent`? | `boolean`                                                                                                      |

### Returns[​](#returns-1 "Direct link to Returns")

`Promise`<`void`>

## Example[​](#example "Direct link to Example")

```
import utils from '@eventcatalog/utils';

const { writeChannel } = utils('/path/to/eventcatalog');

// Write a channel to the catalog
// channel would be written to channels/inventory.{env}.events
await writeChannel({
  id: 'inventory.{env}.events',
  name: 'Inventory channel',
  version: '0.0.1',
  summary: 'This is a summary',
  markdown: '# Hello world',
  address: inventory.{env}.events,
protocols: ['http'],
});

// Write a channel to the catalog but override the path
// channel would be written to channels/Inventory/InventoryChannel
await writeChannel({
   id: 'InventoryChannel',
   name: 'Update Inventory',
   version: '0.0.1',
   summary: 'This is a summary',
   markdown: '# Hello world',
   address: inventory.{env}.events,
   protocols: ['http'],
}, { path: "/channels/Inventory/InventoryChannel"});

// Write a channel to the catalog and override the existing content (if there is any)
await writeChannel({
   id: 'InventoryChannel',
   name: 'Update Inventory',
   version: '0.0.1',
   summary: 'This is a summary',
   markdown: '# Hello world',
   address: inventory.{env}.events,
   protocols: ['http'],
}, { override: true });

// Write a channel to the catalog and version the previous version
// only works if the new version is greater than the previous version
await writeChannel({
   id: 'InventoryChannel',
   name: 'Update Inventory',
   version: '0.0.1',
   summary: 'This is a summary',
   markdown: '# Hello world',
   address: inventory.{env}.events,
   protocols: ['http'],
}, { versionExistingContent: true });
```
