---
# System prepended metadata

title: Config loader
tags: [brew-js]

---

---
tags: brew-js
---

# Config loader

```typescript
import brew from "brew-js/core";
import from "brew-js/extension/config";

interface MyConfig {
    count: number
}

brew<Brew.WithConfig<MyConfig>>((app) => {
    app.useConfig({
        path: 'url/to/config.json',
        // make config unchangeable
        freeze: true,
        // called when the json failed to load
        fallback() {
            return { count: 0 };
            // alternatively load another config or do other stuff
            // return brew.getJSON('another.json');
        }
    });
    app.watch(app.config, 'count', (count) => {
        // called when config loaded
        console.log(count);
    });
    app.on('ready', () => {
        // ready event after config loaded
        console.log(app.config.count);
    });
});
```
