Skip to content

Deno

Layerfig is compatible with Deno. According to the official Deno documentation, Deno provides polyfills for several built-in Node.js APIs, including those Layerfig uses for file loading (node:path and node:fs).

The library is not yet published to jsr (the Deno package registry). However, since Deno supports npm packages, you can install Layerfig using the following command:

deno add npm:@layerfig/config

After installation, follow the setup process described in the Getting Started guide.

The main difference when using Deno is its security model, which restricts access by default. Layerfig needs two permissions:

deno run --allow-read --allow-env --allow-net --watch server.ts

Layerfig defaults to process.env, which Deno polyfills. If you would rather use Deno’s native API — or you want to grant --allow-env for a specific list of variables — pass runtimeEnv yourself:

import { ConfigBuilder, FileSource } from "@layerfig/config";

export const config = new ConfigBuilder({
  validate: (finalConfig) => schema.parse(finalConfig),
  runtimeEnv: Deno.env.toObject(),
})
  .addSource(new FileSource("base.json"))
  .build();

With this setup complete, you can load your configuration files and access the config object throughout your application.