> ## Documentation Index
> Fetch the complete documentation index at: https://pulian.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> Environment files, package auto-loading, and runtime dynamic configs.

# Configuration

## More Examples

Use `package.json` auto-load for integration services that default-export a Hile service:

```json theme={null}
{
  "type": "module",
  "scripts": {
    "dev": "hile start --dev --env-file .env",
    "start": "hile start --env-file .env.prod"
  },
  "hile": {
    "auto_load_packages": ["@hile/logger", "@hile/ioredis", "@hile/typeorm"]
  }
}
```

Inside another service, load dependencies:

```ts theme={null}
import { defineService, loadService } from '@hile/core'
import redisService from '@hile/ioredis'
import typeormService from '@hile/typeorm'

export default defineService('user.service', async () => {
  const [redis, ds] = await Promise.all([
    loadService(redisService),
    loadService(typeormService),
  ])
  return { redis, ds }
})
```

## Complete Example

```ts theme={null}
import { z } from 'zod'
import { MicroDynamicConfigsServer } from '@hile/micro-dynamic-configs'

const schema = z.object({
  featureCheckout: z.boolean().default(false),
  maxRetries: z.number().int().min(1).max(10).default(3),
})

const configs = new MicroDynamicConfigsServer({
  app,
  redis,
  schema,
  redis_key: 'configs:checkout',
})

const cleanup = await configs.initialize()
shutdown(cleanup)

configs.on('change:featureCheckout', (next, previous) => {
  logger.info({ previous, next }, 'featureCheckout changed')
})

await configs.save({ featureCheckout: true })
```

## Failure And Cleanup Behavior

* `save()` validates fields before mutating memory.
* Redis is written before memory and event emission update.
* `initialize()` publishes every config field as a topic.
* Cleanup unpublishes topics and removes listeners.

## Runtime And Lifecycle Notes

* `MessageLoader` maps `*.msg.*` files to routes using `@hile/loader`.
* `MessageLoader.dispatch(path, data, extras?)` invokes the matched handler.
* `MessageModem._send()` returns a `Promise`.
* `MessageModem._stream()` returns a Node `Readable` in object mode.
* A stream request requires `exec()` to return an async iterable.
* `Application.call(namespace, url, data, options?)` returns a promise.
* `Application.stream(namespace, url, data, options?)` returns a readable stream.
* `Application.publish(topic, payload)` returns an object with `update()` and `unpublish()`.
* `Application.subscribe(topic, callback)` returns an unsubscribe function.
* `Registry` stores service addresses and retained config/topic state under `~/.registry`.
