# Services

## What is service?

You can use a service to create messages and work with the db, and your code will be cleaner

## Export message to service

We recommend that you describe the message you will use in the controller in the service and retrieve it with `this.service.message`

{% code title="app.service.ts" %}

```typescript
import { Service } from 'nestgram';

@Service()
export class AppService {
  get helloMessage(): string {
    return 'Hello, world!';
  }
}
```

{% endcode %}

{% code title="app.controller.ts" %}

```typescript
import { OnCommand, Controller } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  async start(): Promise<string> {
    return this.appService.helloMessage;
  }
}
```

{% endcode %}

## Working with db

We recommend to work with db in controllers. It will be more modular. If you'll use database work in services, we will provide you with a good work with it. You can read more about it [here](https://degreetpro.gitbook.io/nestgram/config/modules/mongo-module)
