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

***

# Function: writeEvent()

> **writeEvent**(`directory`): (`event`, `options`) => `Promise`<`void`>

Defined in: events.ts:123

Write an event to EventCatalog.

You can optionally overide the path of the event.

## 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                                                                                                           |
| --------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| `event`                           | `Event`                                                                                                        |
| `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 { writeEvent } = utils('/path/to/eventcatalog');

// Write an event to the catalog
// Event would be written to events/InventoryAdjusted
await writeEvent({
  id: 'InventoryAdjusted',
  name: 'Inventory Adjusted',
  version: '0.0.1',
  summary: 'This is a summary',
  markdown: '# Hello world',
});

// Write an event to the catalog but override the path
// Event would be written to events/Inventory/InventoryAdjusted
await writeEvent({
   id: 'InventoryAdjusted',
   name: 'Inventory Adjusted',
   version: '0.0.1',
   summary: 'This is a summary',
   markdown: '# Hello world',
}, { path: "/Inventory/InventoryAdjusted"});

// Write a event to the catalog and override the existing content (if there is any)
await writeEvent({
   id: 'InventoryAdjusted',
   name: 'Inventory Adjusted',
   version: '0.0.1',
   summary: 'This is a summary',
   markdown: '# Hello world',
}, { override: true });

// Write a event to the catalog and version the previous version
// only works if the new version is greater than the previous version
await writeEvent({
   id: 'InventoryAdjusted',
   name: 'Inventory Adjusted',
   version: '0.0.1',
   summary: 'This is a summary',
   markdown: '# Hello world',
}, { versionExistingContent: true });
```
