# Creating an environment

> Set up Kiln with createKiln and its options.

`createKiln` creates an environment: the object that loads, compiles and renders your templates. Create one when your app starts and reuse it for every render.

```ts
import { createKiln, memoryLoader } from "@lucidkiln/core";

const kiln = createKiln({
	loader: memoryLoader({
		"layouts/base.kiln": "...",
		"pages/home.kiln": "...",
	}),
	functions: {
		document: async (collection: string, query: { slug: string }) =>
			db.find(collection, query),
	},
	globals: { site: { name: "Acme" } },
});

const html = await kiln.render("pages/home", { route: { path: "/" } });
```

## Options

| Option | Default | Description |
| --- | --- | --- |
| `loader` | Required | Where templates come from. See [Loaders](https://kilnlang.com/docs/api/loaders/) |
| `functions` | `{}` | Functions templates can call |
| `filters` | `{}` | Filters templates can use |
| `tests` | `{}` | Tests templates can use with `is` |
| `types` | `{}` | Checks for your own prop types, such as `Post`. See [TypeScript types](https://kilnlang.com/docs/api/types/#your-own-types) |
| `globals` | `{}` | Variables every template can read |
| `strict` | `true` | Whether missing variables and properties are errors. See [Strict mode](https://kilnlang.com/docs/language/strict-mode/) |
| `autoescape` | `"html"` | The escaping strategy for output, or `false` to turn it off |
| `locale` | `"en"` | The locale for `formatNumber`, `plural` and `formatDate` |
| `timeZone` | `"UTC"` | The time zone for `formatDate` |
| `cache` | None | Where the `cache` tag saves output, such as `memoryCache()`. See [cache](https://kilnlang.com/docs/tags/cache/#cache-stores) |
| `cacheNamespace` | `""` | Your app and build identity, added to every fragment cache key. Change it on deployment. See [Deployments and shared stores](https://kilnlang.com/docs/tags/cache/#deployments-and-shared-stores) |
| `htmlChecks` | `true` | Which HTML rules `check` reports, and how. See [HTML checks](https://kilnlang.com/docs/tooling/html-checks/#turning-rules-off) |
| `debug` | `false` | Turns on the `dump` function |
| `limits` | See [Limits](https://kilnlang.com/docs/api/safety/#limits) | Caps on output size, steps and nesting |

`locale` and `timeZone` have fixed defaults rather than the server's settings, so a page renders the same on your laptop, on Node and on Workers.

## The environment

The environment has these methods:

| Method | Description |
| --- | --- |
| `render(name, context?, options?)` | Renders a template to a string. See [Rendering](https://kilnlang.com/docs/api/rendering/) |
| `renderBlock(name, block, context?, options?)` | Renders one block of a template |
| `check(name, source?)` | Finds problems in a template without rendering it. See [Errors and checks](https://kilnlang.com/docs/api/errors/#checking-templates) |
| `analyze(name, source?)` | Reports what a template uses |
| `precompile(name, source?)` | Compiles a template to a JavaScript module at build time. See [Precompiling](https://kilnlang.com/docs/api/precompiling/) |
| `invalidate(name?)` | Clears one compiled template, or all of them, from the cache |
