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

***

# Function: toService()

> **toService**(`directory`): (`file`) => `Promise`<`Service`>

Defined in: services.ts:515

Takes a given raw file and converts it to a service.

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

| Parameter   | Type     | Description                                     |
| ----------- | -------- | ----------------------------------------------- |
| `directory` | `string` | The directory to convert the file to a service. |

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

`Function`

The service.

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

| Parameter | Type     |
| --------- | -------- |
| `file`    | `string` |

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

`Promise`<`Service`>

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

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

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

// Read the file from somewhere
const file = fs.readFileSync('/path/to/services/InventoryService/index.mdx', 'utf8');

// Converts the raw file to a service
await toService(file);
```
